-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
110 lines (85 loc) · 2.14 KB
/
App.js
File metadata and controls
110 lines (85 loc) · 2.14 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import React, { Component } from 'react';
import logo from './logo.svg';
import 'bootstrap/dist/css/bootstrap.min.css'
import './App.css';
import Github from './Github';
import Header from './Components/Header';
import Auth0Lock from 'auth0-lock';
class App extends Component {
constructor(props){
super(props);
this.state = {
idToken: '',
profile: {}
};
}
static defaultProps = {
clientID: 'Sz7rXtT2JeGMs18hSgGUOqeXXOIH4HPI',
domain: 'rupesh1310.auth0.com'
}
componentWillMount(){
this.lock = new Auth0Lock(this.props.clientID, this.props.domain);
this.lock.on('authenticated', (authResult) => {
// console.log(authResult);
this.lock.getProfile(authResult.idToken, (error, profile) => {
if(error){
console.log(error);
return;
}
// console.log(profile);
this.setProfile(authResult.idToken, profile);
});
});
this.getProfile();
}
setProfile(idToken, profile){
localStorage.setItem('idToken', idToken);
localStorage.setItem('profile', JSON.stringify(profile));
this.setState({
idToken: localStorage.getItem('idToken'),
profile: JSON.parse(localStorage.getItem('profile'))
});
}
getProfile(){
if(localStorage.getItem('idToken') != null){
this.setState({
idToken: localStorage.getItem('idToken'),
profile: JSON.parse(localStorage.getItem('profile'))
}, () => {
console.log(this.state);
});
}
}
showLock(){
this.lock.show();
}
logout(){
this.setState({
idToken: '',
profile: ''
}, () => {
localStorage.removeItem('idToken');
localStorage.removeItem('profile');
});
}
render() {
let gitty;
if(this.state.idToken){
gitty = <Github />
} else{
gitty = "Click on Login to view Github Viewer"
}
return (
<div className="App">
<Header
lock={this.lock}
idToken={this.state.idToken}
onLogout={this.logout.bind(this)}
onLogin={this.showLock.bind(this)}
/>
{gitty}
</div>
);
}
}
export default App;