-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathApp.js
More file actions
102 lines (90 loc) · 2.74 KB
/
App.js
File metadata and controls
102 lines (90 loc) · 2.74 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
94
95
96
97
98
99
100
101
102
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, { useState, useEffect } from 'react';
import {
View,
} from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import BottomNavigation from './navigations/BottomNavigation';
import SignUp from './pages/SignUp';
import SignIn from './pages/SignIn';
import Main from './pages/Main';
import firestore from '@react-native-firebase/firestore';
import {firebase} from '@react-native-firebase/auth';
import { getFromStorage } from './services/storage';
const App = () => {
const [isSignedIn, setIsSigned] = useState(false);
const [isInMain, setIsInMain] = useState(true);
const [isInSign, setIsInSignIn] = useState(false);
useEffect(() => {
getFromStorage('remember_auth')
.then(remember_auth => {
console.log('Remember auth: ', remember_auth);
if (remember_auth === 'true') {
const usersRef = firestore().collection('users');
// oturum açan kullanıcının durumunu dinle
firebase.auth().onAuthStateChanged(user => {
console.log(
'Checking if user is signed in before...'
);
if (user) {
usersRef
.doc(user.uid)
.get()
.then(firestoreDocument => {
const userData = firestoreDocument.data();
console.log(
'User already signed in: ' + JSON.stringify(userData),
);
setIsSigned(true);
})
.catch(error => {
console.log(error.toString());
});
}
});
}
})
.catch(error => console.log('Getting remember auth error: ', error));
}, []);
const handle = () =>
{
if(isSignedIn)
{
return (
<NavigationContainer>
<BottomNavigation setIsSigned={setIsSigned}/>
</NavigationContainer>
)
}
else if(isInMain)
return <Main setIsInMain={setIsInMain} setIsInSignIn={setIsInSignIn}></Main>
else if(isInSign)
return <SignIn setIsSigned={setIsSigned} setIsInSignIn={setIsInSignIn}/>
else
return <SignUp setIsSigned={setIsSigned} setIsInSignIn={setIsInSignIn}/>
}
const render = handle();
return (
<View>
{
render
}
</View>
);
};
export default App;
/*
{isSignedIn ? (
<NavigationContainer>
<BottomNavigation setIsSignedIn={setIsSignedIn}/>
</NavigationContainer>
) : isSign ? (
<SignIn setIsSignedIn={setIsSignedIn} setIsSign={setIsSign}/>
) : <SignUp setIsSignedIn={setIsSignedIn} setIsSign={setIsSign}/>}
*/