File tree Expand file tree Collapse file tree 1 file changed +13
-14
lines changed Expand file tree Collapse file tree 1 file changed +13
-14
lines changed Original file line number Diff line number Diff line change @@ -9,9 +9,14 @@ start();
9
9
10
10
async function start ( ) {
11
11
const code = getCode ( ) ;
12
- const { token} = await fetch ( `https://gistbarn.herokuapp.com/authenticate/${ code } ` ) . then ( r => r . json ( ) ) ;
13
- console . log ( { token} ) ;
14
- appState . loggedIn = token ;
12
+ if ( ! code ) {
13
+ const token = localStorage . get ( 'token' ) ;
14
+ appState . loggedIn = token ;
15
+ } else {
16
+ const { token} = await fetch ( `https://gistbarn.herokuapp.com/authenticate/${ code } ` ) . then ( r => r . json ( ) ) ;
17
+ console . log ( { loggedIn :token } ) ;
18
+ appState . loggedIn = token ;
19
+ }
15
20
( await App ( appState ) ) . to ( 'main.app' , 'innerHTML' ) ;
16
21
}
17
22
@@ -74,16 +79,10 @@ function Post(state) {
74
79
` ;
75
80
}
76
81
77
- function UserMenu ( state ) {
78
- return R `<span class=usermenu>${ state . name } </span>` ;
79
- }
80
-
81
- function LogIn ( state ) {
82
- return R `<span class=loginmenu><button class=login>Login</button></span>` ;
83
- }
84
-
85
82
function getCode ( ) {
86
- const code = window . location . search . match ( / \? c o d e = ( .* ) / ) [ 1 ] ;
87
- console . log ( { loggedIn :code } ) ;
88
- return code ;
83
+ try {
84
+ const code = window . location . search . match ( / \? c o d e = ( .* ) / ) [ 1 ] ;
85
+ console . log ( { tempCode :code } ) ;
86
+ return code ;
87
+ } catch ( e ) { return null ; }
89
88
}
You can’t perform that action at this time.
0 commit comments