-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
73 lines (63 loc) · 1.78 KB
/
App.js
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
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, Alert, Button } from 'react-native';
import {
useAuth0,
Auth0Provider
} from 'react-native-auth0'
import config from './auth0-configuration';
const Home = () => {
const {authorize, clearSession, user, error, getCredentials, isLoading} = useAuth0();
const onLogin = async () => {
try {
await authorize();
let credentials = await getCredentials();
console.log(JSON.stringify(credentials))
Alert.alert('AccessToken: ' + credentials.accessToken);
} catch (e) {
console.log(e);
console.log(JSON.stringify(e))
}
};
const loggedIn = user !== undefined && user !== null;
const onLogout = async () => {
try {
await clearSession();
} catch (e) {
console.log('Log out cancelled');
}
};
if (isLoading) {
return <View style={styles.container}><Text>Loading</Text></View>;
}
return (
<View style={styles.container}>
<Text style={styles.header}> Auth0Sample - Login </Text>
{user && <Text>You are logged in as {user.name}</Text>}
{!user && <Text>You are not logged in</Text>}
{error && <Text>{error.message}</Text>}
<Button
onPress={loggedIn ? onLogout : onLogin}
title={loggedIn ? 'Log Out' : 'Log In'}
/>
</View>
);
}
export default function App() {
return (
// <View style={styles.container}>
// <Text>Open up App.js to start working on your app!</Text>
// <StatusBar style="auto" />
// </View>
<Auth0Provider domain={config.domain} clientId={config.clientId}>
<Home />
</Auth0Provider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});