-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthorizedUser.js
45 lines (35 loc) · 1.04 KB
/
AuthorizedUser.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
// import React, {import React from 'react'
// export const Component = (props) => {
// return(
// <div>
// {props.children}
// </div>
// )
// }
// export default Component}
import React, {component} from 'react';
import {withRouter} from 'react-router-dom';
class AuthorizedUser extends component{
state = {signIn: false}
componentDidMount(){
if(window.location.search.match(/code=/)){
this.setState({signIn: true})
const code = window.location.search.replace("?code=", "")
alert(code)
this.props.history.replace('/')
}
}
}
requestCode(){
var clientID = <YOUR_GITHUB_CLIENT_ID>
window.location = ˋhttps://github.com/login.oauth/authorize?client_id=${clientID}&scope=userˋ
}
render(){
return(
<button onClick={this.requestCode} disabled={this.state.signIn}>
Sign In with GitHub
</button>
)
}
}
export default withRouter(AuthorizedUser);