-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.js
More file actions
53 lines (49 loc) · 1.44 KB
/
App.js
File metadata and controls
53 lines (49 loc) · 1.44 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
import React, { useEffect, useState } from "react";
import { ActivityIndicator, Alert, StatusBar, StyleSheet, View } from "react-native";
import Main from './components/Main';
import AsyncStorage from "@react-native-async-storage/async-storage";
import {AuthContext} from "./components/forAuth/AuthContext";
import axios from "axios";
export default function App() {
const [isAuth, setIsAuth] = useState(false)
const [isLoading, setIsLoading] = useState(false)
const checkAuth = async() => {
try{
const token = await AsyncStorage.getItem('token');
if (token != null){
await axios.get('http://192.248.177.166:8000/me',
{headers: {Authorization: 'Bearer ' + token}})
.then(response => {
setIsAuth(true);
})
}
setIsLoading(true)
}catch(e){
Alert.alert("Ошибка", e.message, [
{text: "OK"}])}
}
useEffect(() => {
checkAuth()
},
[]);
return (
<AuthContext.Provider value={{ isAuth, setIsAuth }}>
<View style={styles.container}>
<StatusBar
backgroundColor="#232323" />
{isLoading ?
<Main /> :
<View style={[{marginTop:'50%'}]}>
<ActivityIndicator animating={true} size="large" color="#C5C5C5" />
</View>
}
</View>
</AuthContext.Provider>
);
}
const styles = StyleSheet.create({
container: {
backgroundColor: '#232323',
height: '100%',
},
});