diff --git a/src/components/SettingsBar.tsx b/src/components/SettingsBar.tsx index c7d75a2..b9f461e 100644 --- a/src/components/SettingsBar.tsx +++ b/src/components/SettingsBar.tsx @@ -138,7 +138,7 @@ function SettingsBarContent() { {!hasAccessToken && ( { // use js here to make sure redirect_uri is latest url const url = `https://github.com/login/oauth/authorize?client_id=${ diff --git a/src/components/SideBar.tsx b/src/components/SideBar.tsx index 83c01b9..4b41aac 100644 --- a/src/components/SideBar.tsx +++ b/src/components/SideBar.tsx @@ -173,11 +173,22 @@ async function trySetUpAccessTokenWithCode() { client_id: oauth.clientId, client_secret: oauth.clientSecret, }) - const { access_token: accessToken, scope } = res - if (scope !== 'repo' || !accessToken) { + const { access_token: accessToken, scope, error_description: errorDescription } = res + if (errorDescription) { + const TOKEN_EXPIRED_DESCRIPTION = `The code passed is incorrect or expired.` + if (errorDescription === TOKEN_EXPIRED_DESCRIPTION) { + alert(`Gitako: The OAuth token has expired, please try again.`) + } else { + throw new Error(errorDescription) + } + } else if (scope !== 'repo' || !accessToken) { throw new Error(`Cannot resolve token response: '${JSON.stringify(res)}'`) } - window.history.pushState({}, 'removed code', window.location.pathname.replace(/#.*$/, '')) + window.history.pushState( + {}, + 'removed search param', + window.location.pathname.replace(window.location.search, ''), + ) return accessToken } } catch (err) { diff --git a/src/content.less b/src/content.less index b0ac42f..dbea7de 100644 --- a/src/content.less +++ b/src/content.less @@ -435,6 +435,9 @@ } .access-token { border-bottom: none; // prevent overwrite by github style + .link-button { + cursor: pointer; + } .hint { color: #6a737d; }