-
Notifications
You must be signed in to change notification settings - Fork 0
/
VoiceHub.tsx
43 lines (39 loc) · 1.32 KB
/
VoiceHub.tsx
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
import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";
import Access from "./pages/Access";
import { RootStackParamList } from "./interfaces/RootStackParamList.interface";
import { useAppDispatch } from "./store/hooks";
import Main from "./pages/Main";
import { AuthOnRender } from "./store/actions/auth.actions";
import { auth } from "../firebase";
import { User, onAuthStateChanged } from "firebase/auth";
import {useState, useEffect} from 'react'
export default function VoiceHub() {
const Stack = createStackNavigator<RootStackParamList>();
const dispatch = useAppDispatch();
const [authRef, setAuthRef] = useState<null | User>(null)
onAuthStateChanged(auth, (user) => {
setAuthRef(user ?? null)
dispatch(AuthOnRender())
});
return (
<NavigationContainer>
<Stack.Navigator
screenOptions={{
headerShown: false,
}}
>
{authRef ? (
<Stack.Group>
<Stack.Screen name="Main" component={Main} />
</Stack.Group>
) : (
<Stack.Group>
<Stack.Screen name="Login" component={Access} />
<Stack.Screen name="Register" component={Access} />
</Stack.Group>
)}
</Stack.Navigator>
</NavigationContainer>
);
}