Skip to content

Commit

Permalink
check auth when login
Browse files Browse the repository at this point in the history
  • Loading branch information
leonhartX committed Jan 3, 2021
1 parent 5a83f93 commit febe64d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
23 changes: 22 additions & 1 deletion options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ $(() => {
$('#login-user').text(`${user}${domain}`).attr('href', userLink);
$('#token').attr('href', tokenLink);
})
.then(() => {
auth();
})
.catch(err => {
//not logged in
})
Expand Down Expand Up @@ -412,7 +415,7 @@ function loginGitLabToken(param) {
}

function logout() {
chrome.storage.sync.remove(['scm', 'token', 'user', 'baseUrl', 'googleApiKey'], () => {
chrome.storage.sync.remove(['scm', 'token', 'user', 'baseUrl', 'gapiToken', 'gapiRefreshToken'], () => {
location.reload();
});
chrome.storage.local.get('tab', (item) => {
Expand Down Expand Up @@ -447,4 +450,22 @@ function addStar(token) {
})
.always(resolve);
})
}

function auth() {
return new Promise((resolve, reject) => {
chrome.runtime.sendMessage({
cmd: 'login',
interactive: true
}, token => {
if (token == null) {
reject("can not get oauth token, currently only support Chrome");
} else {
chrome.storage.sync.set({
"gapiToken": token
});
resolve(token);
}
});
});
}
14 changes: 12 additions & 2 deletions src/gas-hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ function load() {
.then(updateBranch)
.then(updateGist)
.then(initPageEvent)
.catch((err) => {
showLog(err, LEVEL_ERROR);
})
break;
case 'not match':
break;
Expand Down Expand Up @@ -342,8 +345,15 @@ function auth() {
cmd: 'login',
interactive: true
}, token => {
context.gapiToken = token;
resolve(token);
if (token == null) {
reject("can not get oauth token, currently only support Chrome");
} else {
context.gapiToken = token;
chrome.storage.sync.set({
"gapiToken": token
});
resolve(token);
}
});
});
}
Expand Down

0 comments on commit febe64d

Please sign in to comment.