Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a97df51

Browse files
committed
Improved login.
1 parent c7c0eb7 commit a97df51

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/app.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ start();
99

1010
async function start() {
1111
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+
}
1520
(await App(appState)).to('main.app', 'innerHTML');
1621
}
1722

@@ -74,16 +79,10 @@ function Post(state) {
7479
`;
7580
}
7681

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-
8582
function getCode() {
86-
const code = window.location.search.match(/\?code=(.*)/)[1];
87-
console.log({loggedIn:code});
88-
return code;
83+
try {
84+
const code = window.location.search.match(/\?code=(.*)/)[1];
85+
console.log({tempCode:code});
86+
return code;
87+
} catch(e) { return null; }
8988
}

0 commit comments

Comments
 (0)