-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfirebaseApp.jsx
More file actions
93 lines (79 loc) · 2.32 KB
/
firebaseApp.jsx
File metadata and controls
93 lines (79 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import {Button, StyleSheet, Text, View} from 'react-native';
import React, {useEffect, useState} from 'react';
import auth from '@react-native-firebase/auth';
import GoogleSignIn from './googleSignIn';
import CloudMessaging from './cloudMessaging';
import Analytics from './analytics';
import FireBaseStore from './firebaseStore';
export default function FirebaseApp() {
const loginAnonymous = () => {
auth()
.signInAnonymously()
.then(data => {
console.log('User signed in anonymously', data);
})
.catch(error => {
if (error.code === 'auth/operation-not-allowed') {
console.log('Enable anonymous in your firebase console.');
}
console.error(error);
});
};
const loginWithEmail = () => {
auth()
.signInWithEmailAndPassword(
'bsbocean.tech@gmail.com',
'SuperSecretPassword!',
)
.then(() => {
console.log('User account created & signed in!');
})
.catch(error => {
if (error.code === 'auth/email-already-in-use') {
console.log('That email address is already in use!');
}
if (error.code === 'auth/invalid-email') {
console.log('That email address is invalid!');
}
console.error(error);
});
};
const logout=()=>{
auth()
.signOut()
.then(() => console.log('User signed out!'));
}
// Set an initializing state whilst Firebase connects
const [initializing, setInitializing] = useState(true);
const [user, setUser] = useState();
// Handle user state changes
function onAuthStateChanged(user) {
setUser(user);
if (initializing) setInitializing(false);
}
useEffect(() => {
const subscriber = auth().onAuthStateChanged(onAuthStateChanged);
return subscriber; // unsubscribe on unmount
}, []);
if (initializing) return null;
if (!user) {
return (
<View>
<Text>Login</Text>
<Button title="Login With Email" onPress={loginWithEmail} />
</View>
);
}
return (
<View>
<Text>Welcome {user.email}</Text>
{/* <GoogleSignIn /> */}
{/* <CloudMessaging /> */}
{/* <Analytics />
*/}
<FireBaseStore />
<Button title='logout' onPress={logout}/>
</View>
);
}
const styles = StyleSheet.create({});