-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
38 lines (37 loc) · 1.35 KB
/
Copy pathApp.js
File metadata and controls
38 lines (37 loc) · 1.35 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
import { StatusBar } from "expo-status-bar";
import MainNavigator, { BottomTabs } from "./navigation/MainNavigator";
import { NavigationContainer } from "@react-navigation/native";
import { useEffect, useState } from "react";
import AsyncStorage from "@react-native-async-storage/async-storage";
import "expo-dev-client";
import LoginScreen from "./screens/LoginScreen";
import { PlayerContextProvider } from "./context/PlayerContext";
export default function App() {
const [isAuth, setIsAuth] = useState(false);
useEffect(() => {
const checkExpirationDate = async () => {
const expirationDate = await AsyncStorage.getItem("expirationDate");
if (!expirationDate) return;
const now = new Date();
if (new Date(expirationDate) > now) {
//* token süresi dolmamış.
setIsAuth(true);
} else {
setIsAuth(false);
AsyncStorage.removeItem("token");
AsyncStorage.removeItem("expirationDate");
}
};
checkExpirationDate();
}, []);
return (
<PlayerContextProvider>
<NavigationContainer>
{/* //* isAuth true ise MainNavigator açılır, false ise LoginScreen açılır. */}
{isAuth ? <BottomTabs /> : <LoginScreen setIsAuth={setIsAuth} />}
{/* <BottomTabs /> */}
<StatusBar style="light" />
</NavigationContainer>
</PlayerContextProvider>
);
}