-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathApp.js
More file actions
43 lines (36 loc) · 989 Bytes
/
App.js
File metadata and controls
43 lines (36 loc) · 989 Bytes
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 React, { Component } from 'react';
import * as querystring from 'query-string';
import {
View,
AsyncStorage,
Linking,
} from 'react-native';
import Login from './screens/Login';
import Home from './screens/Home';
export default class App extends Component {
state = {
loggedIn: false,
}
componentDidMount() {
Linking.addEventListener('url', this.handleOauthCallback);
}
componentWillUnmount() {
Linking.removeEventListener('url', this.handleOauthCallback);
}
handleOauthCallback = async (event) => {
const loginInfo = querystring.parse(event.url.split('#')[1]);
await AsyncStorage.setItem('@df17:instanceUrl', loginInfo.instance_url);
await AsyncStorage.setItem('@df17:accessToken', loginInfo.access_token);
this.setState({
loggedIn: true,
});
}
render() {
return (
<View style={{flex: 1}}>
{!this.state.loggedIn && <Login />}
{this.state.loggedIn && <Home/>}
</View>
);
}
}