File tree 5 files changed +54
-18
lines changed
5 files changed +54
-18
lines changed Original file line number Diff line number Diff line change 1
- import React , { FC , useEffect } from 'react' ;
1
+ import React , { FC } from 'react' ;
2
2
import 'react-native-gesture-handler' ;
3
3
import { Provider } from 'react-redux' ;
4
4
import { store } from './src/redux/store' ;
@@ -8,6 +8,8 @@ import { tomorrowFonts } from './src/assets';
8
8
import { firebaseConfig } from './src/utils' ;
9
9
import * as firebase from 'firebase' ;
10
10
11
+ firebase . initializeApp ( firebaseConfig ) ;
12
+
11
13
const App : FC = ( ) => {
12
14
const [ fontsLoaded ] = useFonts ( {
13
15
'Tomorrow-Regular' : tomorrowFonts . regular ,
@@ -16,11 +18,6 @@ const App: FC = () => {
16
18
'Tomorrow-SemiBold' : tomorrowFonts . semiBold ,
17
19
'Tomorrow-ExtraBold' : tomorrowFonts . extraBold ,
18
20
} ) ;
19
-
20
-
21
- useEffect ( ( ) => {
22
- firebase . initializeApp ( firebaseConfig ) ;
23
- } , [ ] ) ;
24
21
25
22
if ( ! fontsLoaded ) {
26
23
return < > </ > ;
Original file line number Diff line number Diff line change 11
11
"@eva-design/eva" : " ^2.0.0" ,
12
12
"@expo-google-fonts/inter" : " ^0.1.0" ,
13
13
"@expo/vector-icons" : " ^10.2.1" ,
14
+ "@react-native-community/async-storage" : " ^1.12.0" ,
14
15
"@react-native-community/masked-view" : " 0.1.10" ,
15
16
"@react-native-firebase/app" : " ^8.4.3" ,
16
17
"@react-native-firebase/auth" : " ^9.2.3" ,
Original file line number Diff line number Diff line change 1
1
import { RootEpic } from '.' ;
2
2
import { AuthTypes , setMessage , setError } from '..' ;
3
3
import { map , filter , switchMap , catchError } from 'rxjs/operators' ;
4
- import { of } from 'rxjs' ;
4
+ import { of , from } from 'rxjs' ;
5
5
import { isOfType } from 'typesafe-actions' ;
6
-
7
- import { signInWithGoogle } from '../../repos' ;
6
+ import AsyncStorage from '@react-native-community/async-storage' ;
7
+ import { signInWithGoogle , Storage } from '../../repos' ;
8
8
9
9
export const welcomeEpic : RootEpic = ( $action ) => {
10
10
return $action . pipe (
@@ -19,9 +19,11 @@ export const loginWithGoogleEpic: RootEpic = ($action) => {
19
19
switchMap ( ( action ) => {
20
20
const { accessToken } = action . payload ;
21
21
return signInWithGoogle ( accessToken ) . pipe (
22
- map ( ( res ) => {
23
- console . log ( res ) ;
24
- return setMessage ( 'logged in' ) ;
22
+ switchMap ( ( res ) => {
23
+ console . log ( 'res' , res ) ;
24
+ return from ( AsyncStorage . setItem ( Storage . Email , res as string ) ) . pipe (
25
+ map ( ( ) => setMessage ( 'logged' ) )
26
+ ) ;
25
27
} ) ,
26
28
catchError ( ( error ) => {
27
29
console . log ( error ) ;
Original file line number Diff line number Diff line change 1
1
import { FirebaseCollectionReference } from '../../utils' ;
2
2
import firebase from 'firebase' ;
3
- import { Observable , from , combineLatest } from 'rxjs' ;
3
+ import { Observable } from 'rxjs' ;
4
+
5
+ export enum Roles {
6
+ Client = 'Client' ,
7
+ Admin = 'Admin' ,
8
+ Manager = 'Manager' ,
9
+ }
10
+
11
+ export enum Storage {
12
+ Email = 'Email' ,
13
+ }
4
14
export interface User {
5
15
id : string ;
6
16
email : string ;
7
17
username : string ;
8
- role ?: [ string ] ;
18
+ role ?: [ Roles ] ;
9
19
phoneNumber ?: string ;
20
+ avatar ?: string ;
10
21
}
11
22
12
23
export const signInWithGoogle = ( accessToken : string ) => {
@@ -18,7 +29,32 @@ export const signInWithGoogle = (accessToken: string) => {
18
29
firebase
19
30
. auth ( )
20
31
. signInWithCredential ( credential )
21
- . then ( ( res ) => observer . next ( res ) )
22
- . catch ( ( ) => observer . error ( 'Something went wrong. Try again' ) ) ;
32
+ . then ( ( res ) => {
33
+ if ( res . user ) {
34
+ const { email, displayName, photoURL } = res . user ;
35
+ return FirebaseCollectionReference . users ( )
36
+ . where ( 'email' , '==' , email )
37
+ . get ( )
38
+ . then ( ( user ) => {
39
+ if ( user . empty ) {
40
+ return FirebaseCollectionReference . users ( )
41
+ . add ( {
42
+ ...res . user ,
43
+ email,
44
+ username : displayName ,
45
+ avatar : photoURL ,
46
+ role : [ Roles . Client ] ,
47
+ } )
48
+ . then ( ( ) => observer . next ( email ) ) ;
49
+ } else {
50
+ observer . next ( email ) ;
51
+ }
52
+ } ) ;
53
+ }
54
+ } )
55
+ . catch ( ( error ) => {
56
+ console . log ( error ) ;
57
+ observer . error ( 'Something went wrong. Try again' ) ;
58
+ } ) ;
23
59
} ) ;
24
60
} ;
Original file line number Diff line number Diff line change 1
- import * as firebase from 'firebase' ;
1
+ import { firestore } from 'firebase' ;
2
+ import 'firebase/firestore' ;
2
3
3
- const { firestore } = firebase ;
4
4
export enum firebaseCollection {
5
5
users = 'users' ,
6
6
books = 'books' ,
You can’t perform that action at this time.
0 commit comments