Commit d73005b 1 parent 720e38f commit d73005b Copy full SHA for d73005b
File tree 3 files changed +54
-25
lines changed
3 files changed +54
-25
lines changed Original file line number Diff line number Diff line change @@ -58,21 +58,30 @@ const RightPane = styled('div')({
58
58
function App ( ) {
59
59
return (
60
60
< Container >
61
- < BungieLogin />
62
- < HeaderContainer >
63
- < SingleDiamondButton />
64
- </ HeaderContainer >
65
- < ContentContainer >
66
- < LeftPane >
67
- < NumberBoxes />
68
- </ LeftPane >
69
- < RightPane >
70
- < h1 style = { { fontSize : '16px' } } > Armour Combinations</ h1 >
71
- < StatsTable />
72
- </ RightPane >
73
- </ ContentContainer >
61
+ < BungieLogin > { ( { isLoggedIn } ) => (
62
+ < div >
63
+ { isLoggedIn ? (
64
+ < Container >
65
+ < HeaderContainer >
66
+ < SingleDiamondButton />
67
+ </ HeaderContainer >
68
+ < ContentContainer >
69
+ < LeftPane >
70
+ < NumberBoxes />
71
+ </ LeftPane >
72
+ < RightPane >
73
+ < h1 style = { { fontSize : '16px' } } > Armour Combinations</ h1 >
74
+ < StatsTable />
75
+ </ RightPane >
76
+ </ ContentContainer >
77
+ </ Container >
78
+ ) : (
79
+ < div > Please log in to continue...</ div >
80
+ ) }
81
+ </ div >
82
+ ) }
83
+ </ BungieLogin >
74
84
</ Container >
75
-
76
85
) ;
77
86
}
78
87
Original file line number Diff line number Diff line change 1
1
import BungieAuth from "../../../lib/BungieAuth"
2
- import React , { useEffect } from "react"
2
+ import React , { Component } from "react"
3
3
4
- export default ( ) => {
4
+ class BungieLogin extends Component {
5
+ constructor ( props ) {
6
+ super ( props )
5
7
6
- function onLogIn ( ) {
7
- BungieAuth . authenticate ( )
8
+ this . state = {
9
+ isLoggedIn : BungieAuth . isAuthenticated ( )
10
+ }
8
11
}
9
12
10
- useEffect ( ( ) => {
13
+ componentDidMount ( ) {
11
14
if ( BungieAuth . setAuthCode ( ) ) {
12
15
BungieAuth . generateToken ( )
13
16
}
14
- } , [ ] )
17
+ }
18
+
19
+ onLogIn ( ) {
20
+ BungieAuth . authenticate ( )
21
+ }
22
+
23
+ onLogOut ( ) {
24
+ // TODO: log out
25
+ }
26
+
27
+ render ( ) {
28
+ return < div >
29
+ { this . props . children ( { isLoggedIn : this . state . isLoggedIn } ) }
30
+ { this . state . isLoggedIn ? ( < button onClick = { this . onLogOut } > Log Out</ button > ) : ( < button onClick = { this . onLogIn } > Log In</ button > ) }
31
+ </ div >
32
+ }
33
+ }
15
34
16
- return BungieAuth . isAuthenticated ( ) ? null : ( < button onClick = { onLogIn } > Log In</ button > )
17
- }
35
+ export default BungieLogin
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ const BungieAuth = {
25
25
} )
26
26
27
27
if ( refreshToken && Date . now ( ) < refreshTokenExpiringAt && Date . now ( ) > lastRefresh + timing ) {
28
- return generateToken ( true )
28
+ return BungieAuth . generateToken ( true )
29
29
}
30
30
31
31
return true
@@ -52,15 +52,17 @@ const BungieAuth = {
52
52
localStorage . setItem ( "refreshToken" , response . data . refresh_token )
53
53
localStorage . setItem ( "refreshTokenExpiringAt" , Date . now ( ) + response . data . refresh_expires_in * 1000 - 10 * 1000 )
54
54
localStorage . setItem ( "lastRefresh" , Date . now ( ) )
55
+ return true
55
56
}
56
57
else {
57
- return new Error ( 'Could not get access token' )
58
+ console . log ( "Could not get access token" )
59
+ return false
58
60
}
59
61
} )
60
62
} ,
61
63
62
64
isAuthenticated : ( ) => {
63
- return ( localStorage . getItem ( "accessToken" ) !== null )
65
+ return ( localStorage . getItem ( "accessToken" ) !== null && BungieAuth . autoRegenerateTokens ( ) )
64
66
} ,
65
67
66
68
setAuthCode : ( ) => {
You can’t perform that action at this time.
0 commit comments