Skip to content

Commit febe64d

Browse files
committed
check auth when login
1 parent 5a83f93 commit febe64d

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

options/options.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ $(() => {
7777
$('#login-user').text(`${user}${domain}`).attr('href', userLink);
7878
$('#token').attr('href', tokenLink);
7979
})
80+
.then(() => {
81+
auth();
82+
})
8083
.catch(err => {
8184
//not logged in
8285
})
@@ -412,7 +415,7 @@ function loginGitLabToken(param) {
412415
}
413416

414417
function logout() {
415-
chrome.storage.sync.remove(['scm', 'token', 'user', 'baseUrl', 'googleApiKey'], () => {
418+
chrome.storage.sync.remove(['scm', 'token', 'user', 'baseUrl', 'gapiToken', 'gapiRefreshToken'], () => {
416419
location.reload();
417420
});
418421
chrome.storage.local.get('tab', (item) => {
@@ -447,4 +450,22 @@ function addStar(token) {
447450
})
448451
.always(resolve);
449452
})
453+
}
454+
455+
function auth() {
456+
return new Promise((resolve, reject) => {
457+
chrome.runtime.sendMessage({
458+
cmd: 'login',
459+
interactive: true
460+
}, token => {
461+
if (token == null) {
462+
reject("can not get oauth token, currently only support Chrome");
463+
} else {
464+
chrome.storage.sync.set({
465+
"gapiToken": token
466+
});
467+
resolve(token);
468+
}
469+
});
470+
});
450471
}

src/gas-hub.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ function load() {
4949
.then(updateBranch)
5050
.then(updateGist)
5151
.then(initPageEvent)
52+
.catch((err) => {
53+
showLog(err, LEVEL_ERROR);
54+
})
5255
break;
5356
case 'not match':
5457
break;
@@ -342,8 +345,15 @@ function auth() {
342345
cmd: 'login',
343346
interactive: true
344347
}, token => {
345-
context.gapiToken = token;
346-
resolve(token);
348+
if (token == null) {
349+
reject("can not get oauth token, currently only support Chrome");
350+
} else {
351+
context.gapiToken = token;
352+
chrome.storage.sync.set({
353+
"gapiToken": token
354+
});
355+
resolve(token);
356+
}
347357
});
348358
});
349359
}

0 commit comments

Comments
 (0)