Skip to content

Commit

Permalink
firebase fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny dhama committed Jun 10, 2020
1 parent 6836fac commit b5f52fb
Show file tree
Hide file tree
Showing 15 changed files with 303 additions and 136 deletions.
21 changes: 19 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
{
"expo": {
"name": "JIIT Companion",
"slug": "jiit-companion",
"slug": "jiit-linked",
"platforms": ["ios", "android", "web"],
"version": "2.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"scheme": "jiitcompanion",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"resizeMode": "cover",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": ["**/*"],
"web": {
"config": {
"firebase": {
"apiKey": "AIzaSyCGfQbubv4Hrq9E_TQXyth2VCmPFdTY-J8",
"authDomain": "jiitcompanion-new-4c6fb.firebaseapp.com",
"databaseURL": "https://jiitcompanion-new-4c6fb.firebaseio.com",
"projectId": "jiitcompanion-new-4c6fb",
"storageBucket": "jiitcompanion-new-4c6fb.appspot.com",
"messagingSenderId": "1075874025858",
"appId": "1:1075874025858:web:b9d6d5961e5895786f3f9b",
"measurementId": "G-88F2CV0EVL"
}
}
},
"ios": {
"infoPlist": {
"NSFaceIDUsageDescription": "Requires FaceID To protect your CGPA Info"
},
"supportsTablet": false,
"bundleIdentifier": "com.sunnydhama.jiitcompanion",
"buildNumber": "1.1.0",
"googleServicesFile": "./firebase/GoogleService-Info.plist",
"config": {
"googleMobileAdsAppId": "ca-app-pub-1528058450389133~3396166750"
}
},
"android": {
"googleServicesFile": "./firebase/google-services.json",
"package": "me.sunnydhama.jiitcompanion",
"versionCode": 23,
"playStoreUrl": "https://play.google.com/store/apps/details?id=me.sunnydhama.jiitcompanion",
Expand Down
18 changes: 9 additions & 9 deletions contexts/auth.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useState } from 'react';
import { AsyncStorage } from 'react-native';
import firebase from 'firebase';
import React, { useState } from "react";
import { AsyncStorage } from "react-native";
import * as Analytics from "expo-firebase-analytics";

import { getAttendance, getDateWiseAttendance } from '../api';
import { useUser } from './user';
import { addUserToDB } from '../firebase';
import { getAttendance, getDateWiseAttendance } from "../api";
import { useUser } from "./user";
import { addUserToDB } from "../firebase";

const AuthContext = React.createContext();

Expand Down Expand Up @@ -41,12 +41,12 @@ export const AuthProvider = ({ children }) => {
user.attendance = attendance;
user.datewiseattendance = datewiseattendance;
addUserToDB(user);
firebase.analytics().logEvent('login_success');
await AsyncStorage.setItem('user', JSON.stringify(user));
Analytics.logEvent("login_success");
await AsyncStorage.setItem("user", JSON.stringify(user));
setUser(user);
setisAuthenticated(true);
} catch (e) {
firebase.analytics().logEvent('login_failed');
Analytics.logEvent("login_failed");
console.log(e);
}
};
Expand Down
36 changes: 18 additions & 18 deletions contexts/user.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useState, useEffect } from 'react';
import firebase from 'firebase';
import { getSubjectString, getDayNumber } from '../utils';
import { getTimeTable, getAttendance } from '../api';
import { AsyncStorage } from 'react-native';
import { firebaseLogin } from '../firebase';
import React, { useState, useEffect } from "react";
import * as Analytics from "expo-firebase-analytics";
import { getSubjectString, getDayNumber } from "../utils";
import { getTimeTable, getAttendance } from "../api";
import { AsyncStorage } from "react-native";
import { firebaseLogin } from "../firebase";

const UserContext = React.createContext();

Expand All @@ -13,12 +13,12 @@ export const UserProvider = ({ children }) => {
const [loading, setLoading] = useState(false);

const _getTimeTable = async (refresh) => {
firebase.analytics().logEvent('get_timetable_called');
Analytics.logEvent("get_timetable_called");

// if no user
if (!user) return;
// if timtable cached
let cachedTimeTable = await AsyncStorage.getItem('timetable');
let cachedTimeTable = await AsyncStorage.getItem("timetable");
cachedTimeTable = JSON.parse(cachedTimeTable);
// if no refresh request and has cache timetable
if (cachedTimeTable && !refresh) {
Expand All @@ -30,14 +30,14 @@ export const UserProvider = ({ children }) => {
let attendance = getSubjectString(user.attendance);
let res = await getTimeTable(attendance, user.batch, user.year);
let timetable = [
{ monday: res['monday'] },
{ tuesday: res['tuesday'] },
{ wednesday: res['wednesday'] },
{ thursday: res['thursday'] },
{ friday: res['friday'] },
{ saturday: res['saturday'] },
{ monday: res["monday"] },
{ tuesday: res["tuesday"] },
{ wednesday: res["wednesday"] },
{ thursday: res["thursday"] },
{ friday: res["friday"] },
{ saturday: res["saturday"] },
];
await AsyncStorage.setItem('timetable', JSON.stringify(timetable));
await AsyncStorage.setItem("timetable", JSON.stringify(timetable));

// set timetable
settimeTable(timetable);
Expand All @@ -51,7 +51,7 @@ export const UserProvider = ({ children }) => {
};

const refreshAttendance = async () => {
firebase.analytics().logEvent('refresh_attendance_called');
Analytics.logEvent("refresh_attendance_called");

if (!user) return;

Expand All @@ -63,7 +63,7 @@ export const UserProvider = ({ children }) => {
return;
}
await AsyncStorage.setItem(
'user',
"user",
JSON.stringify({
...user,
attendance,
Expand All @@ -82,7 +82,7 @@ export const UserProvider = ({ children }) => {
[dayName]: data,
};
settimeTable(newTimeTable);
await AsyncStorage.setItem('timetable', JSON.stringify(newTimeTable));
await AsyncStorage.setItem("timetable", JSON.stringify(newTimeTable));
};

useEffect(() => {
Expand Down
36 changes: 36 additions & 0 deletions firebase/GoogleService-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CLIENT_ID</key>
<string>1075874025858-9f4trp9rosj313js3esdib5d6r5i2jdj.apps.googleusercontent.com</string>
<key>REVERSED_CLIENT_ID</key>
<string>com.googleusercontent.apps.1075874025858-9f4trp9rosj313js3esdib5d6r5i2jdj</string>
<key>API_KEY</key>
<string>AIzaSyDUv5INJWbs43WHJCfptbcvLxS69U5wadE</string>
<key>GCM_SENDER_ID</key>
<string>1075874025858</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>com.sunnydhama.jiitcompanion</string>
<key>PROJECT_ID</key>
<string>jiitcompanion-new-4c6fb</string>
<key>STORAGE_BUCKET</key>
<string>jiitcompanion-new-4c6fb.appspot.com</string>
<key>IS_ADS_ENABLED</key>
<false></false>
<key>IS_ANALYTICS_ENABLED</key>
<false></false>
<key>IS_APPINVITE_ENABLED</key>
<true></true>
<key>IS_GCM_ENABLED</key>
<true></true>
<key>IS_SIGNIN_ENABLED</key>
<true></true>
<key>GOOGLE_APP_ID</key>
<string>1:1075874025858:ios:1d1e10f2eca516596f3f9b</string>
<key>DATABASE_URL</key>
<string>https://jiitcompanion-new-4c6fb.firebaseio.com</string>
</dict>
</plist>
47 changes: 47 additions & 0 deletions firebase/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"project_info": {
"project_number": "1075874025858",
"firebase_url": "https://jiitcompanion-new-4c6fb.firebaseio.com",
"project_id": "jiitcompanion-new-4c6fb",
"storage_bucket": "jiitcompanion-new-4c6fb.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:1075874025858:android:3dd1e053bcb9cb5f6f3f9b",
"android_client_info": {
"package_name": "me.sunnydhama.jiitcompanion"
}
},
"oauth_client": [
{
"client_id": "1075874025858-ted68103ndgsokjnpmso536istco8ejk.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyDnZaklFmrGSzwIDq50mgaj6QZHOC0etoY"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "1075874025858-ted68103ndgsokjnpmso536istco8ejk.apps.googleusercontent.com",
"client_type": 3
},
{
"client_id": "1075874025858-9f4trp9rosj313js3esdib5d6r5i2jdj.apps.googleusercontent.com",
"client_type": 2,
"ios_info": {
"bundle_id": "com.sunnydhama.jiitcompanion"
}
}
]
}
}
}
],
"configuration_version": "1"
}
19 changes: 9 additions & 10 deletions firebase/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import firebase from 'firebase';

import { firebaseConfig } from './firebaseConfig';
import firebase from "firebase";
import { firebaseConfig } from "./firebaseConfig";

export const firebaseInit = () => {
try {
firebase.initializeApp(firebaseConfig);
firebase.analytics();
if (!firebase.apps.length) firebase.initializeApp(firebaseConfig);
console.log("firebase init success");
} catch (err) {
console.log('Firebase Init failed');
console.log("Firebase Init failed");
console.log(err);
}
};
Expand All @@ -16,8 +15,8 @@ export const firebaseLogin = async ({ email, password }) => {
try {
await firebase.auth().signInWithEmailAndPassword(email, password);
} catch (err) {
console.log('Firebase login failed');
if (err.code == 'auth/user-not-found') firebaseSignUp({ email, password });
console.log("Firebase login failed");
if (err.code == "auth/user-not-found") firebaseSignUp({ email, password });
}
};

Expand All @@ -26,7 +25,7 @@ export const firebaseSignUp = async ({ email, password }) => {
await firebase.auth().createUserWithEmailAndPassword(email, password);
await firebaseLogin({ email, password });
} catch (err) {
console.log('Firebase login failed');
console.log("Firebase login failed");
console.log(err);
}
};
Expand All @@ -50,7 +49,7 @@ export const addUserToDB = async ({
college,
});
} catch (err) {
console.log('Firebase add user to DB failed');
console.log("Firebase add user to DB failed");
console.log(err);
}
};
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"expo-asset": "~8.1.5",
"expo-camera": "~8.2.0",
"expo-constants": "~9.0.0",
"expo-firebase-analytics": "~2.1.1",
"expo-firebase-core": "~1.0.0",
"expo-font": "~8.1.0",
"expo-image-picker": "~8.1.0",
"expo-local-authentication": "~9.0.0",
Expand All @@ -36,10 +38,13 @@
"react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
"react-native-animatable": "^1.3.3",
"react-native-appearance": "~0.3.3",
"react-native-calendars": "^1.294.0",
"react-native-circular-progress": "^1.3.6",
"react-native-dark-mode": "^0.2.2",
"react-native-draggable-flatlist": "^2.3.3",
"react-native-dropdownalert": "^4.2.1",
"react-native-gesture-handler": "~1.6.0",
"react-native-modal": "^11.5.6",
"react-native-reanimated": "~1.7.0",
"react-native-safe-area-context": "0.7.3",
"react-native-screens": "~2.2.0",
Expand Down
16 changes: 8 additions & 8 deletions screens/App/Attendance/Attendance.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, { useEffect } from 'react';
import React, { useEffect } from "react";
import {
ScrollView,
StyleSheet,
RefreshControl,
StatusBar,
} from 'react-native';
import firebase from 'firebase';
} from "react-native";
import * as Analytics from "expo-firebase-analytics";

import { AttendanceDayConatiner } from '../../../components';
import { useTheme, useUser } from '../../../contexts';
import { Mixins, Typography } from '../../../styles';
import { AttendanceDayConatiner } from "../../../components";
import { useTheme, useUser } from "../../../contexts";
import { Mixins, Typography } from "../../../styles";

const Attendance = () => {
const {
Expand All @@ -22,14 +22,14 @@ const Attendance = () => {
let classes = Object.keys(user.attendance);

useEffect(() => {
firebase.analytics().logEvent('attendance_screen_view');
Analytics.logEvent("attendance_screen_view");
}, []);

if (!classes?.length) return <> </>;
return (
<>
<StatusBar
barStyle={dark ? 'light-content' : 'dark-content'}
barStyle={dark ? "light-content" : "dark-content"}
backgroundColor={black}
animated
/>
Expand Down
12 changes: 6 additions & 6 deletions screens/App/Cgpa/Cgpa.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useEffect } from 'react';
import { StyleSheet, Text, View, ScrollView } from 'react-native';
import firebase from 'firebase';
import React, { useEffect } from "react";
import { StyleSheet, Text, View, ScrollView } from "react-native";
import * as Analytics from "expo-firebase-analytics";

import { useTheme } from '../../../contexts';
import { Mixins, Typography } from '../../../styles';
import { useTheme } from "../../../contexts";
import { Mixins, Typography } from "../../../styles";
const Cgpa = () => {
const {
theme: {
Expand All @@ -12,7 +12,7 @@ const Cgpa = () => {
} = useTheme();

useEffect(() => {
firebase.analytics().logEvent('cgpa_page_view');
Analytics.logEvent("cgpa_page_view");
}, []);

return (
Expand Down
Loading

0 comments on commit b5f52fb

Please sign in to comment.