Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Refresh access_token if expired #24

Merged
merged 9 commits into from Nov 5, 2020
Next

try to refresh token if get fails

  • Loading branch information
fcjr committed Nov 5, 2020
commit ec1a1e0fcfb84b9010a866b76b1d2f6341a44d85
@@ -11,8 +11,12 @@ class AccessToken {
tokenPool.generateTokens();
}

static get() {
return AccessToken.TOKEN;
static async get() {
if (AccessToken.TOKEN) {
return AccessToken.TOKEN
}
await AccessToken.refresh();
return AccessToken.TOKEN
}

static destroy() {
@@ -39,7 +39,7 @@ class TokenPool {
}

async generateTokens() {
const accessToken = AccessToken.get();
const accessToken = await AccessToken.get();
This conversation was marked as resolved by fcjr

This comment has been minimized.

@sammacbeth

sammacbeth Nov 5, 2020
Contributor

If this calls AccessToken.refresh() and the access token cookie is updated, AccessToken.set will call generateTokens (https://github.com/ghostery/ghostery-search-extension/blob/master/src/background.js#L11) so this will actually end up calling generateTokens twice.

if (!accessToken) {
return;
}
ProTip! Use n and p to navigate between commits in a pull request.