Skip to content

Commit

Permalink
fix: trigger login flow if refreshtoken isn't valid
Browse files Browse the repository at this point in the history
If the auth refresh token isn't valid, then we should trigger the login flow. Reported in #316
  • Loading branch information
threepointone committed Mar 26, 2022
1 parent 52ea60f commit 445ca60
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changeset/late-mayflies-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

fix: trigger login flow if refreshtoken isn't valid

If the auth refresh token isn't valid, then we should trigger the login flow. Reported in https://github.com/cloudflare/wrangler2/issues/316
10 changes: 7 additions & 3 deletions packages/wrangler/src/user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,7 @@ export async function getAuthURL(scopes = ScopeKeys): Promise<string> {
`?response_type=code&` +
`client_id=${encodeURIComponent(CLIENT_ID)}&` +
`redirect_uri=${encodeURIComponent(CALLBACK_URL)}&` +
// @ts-expect-error we add offline_access manually
`scope=${encodeURIComponent(scopes.concat("offline_access").join(" "))}&` +
`scope=${encodeURIComponent([...scopes, "offline_access"].join(" "))}&` +
`state=${stateQueryParam}&` +
`code_challenge=${encodeURIComponent(codeChallenge)}&` +
`code_challenge_method=S256`
Expand Down Expand Up @@ -864,7 +863,12 @@ export async function loginOrRefreshIfRequired(
// If we are not interactive, we cannot ask the user to login
return isInteractive && (await login());
} else if (isAccessTokenExpired()) {
return await refreshToken();
const didRefresh = await refreshToken();
if (didRefresh) {
return true;
} else {
return isInteractive && (await login());
}
} else {
return true;
}
Expand Down

0 comments on commit 445ca60

Please sign in to comment.