-
Notifications
You must be signed in to change notification settings - Fork 753
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: trigger login flow if refreshtoken isn't valid #709
Conversation
🦋 Changeset detectedLatest commit: e974c7b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.developers.workers.dev/runs/2044856879/npm-package-wrangler-709 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/709/npm-package-wrangler-709 Or you can use npx https://prerelease-registry.developers.workers.dev/runs/2044856879/npm-package-wrangler-709 dev path/to/script.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On minor suggestion.
packages/wrangler/src/user.tsx
Outdated
const didRefresh = await refreshToken(); | ||
if (didRefresh) { | ||
return true; | ||
} else { | ||
return isInteractive && (await login()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could simply be...
const didRefresh = await refreshToken(); | |
if (didRefresh) { | |
return true; | |
} else { | |
return isInteractive && (await login()); | |
} | |
return await refreshToken() || isInteractive && (await login()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my first take, but I landed on this version because it reads better. I'll add a comment.
@@ -610,8 +610,8 @@ 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
If the auth refresh token isn't valid, then we should trigger the login flow. Reported in #316
bad6374
to
e974c7b
Compare
If the auth refresh token isn't valid, then we should trigger the login flow. Reported in #316
We don't have any test coverage on this complicated login machinery 😓 We should fix that soon. I wish there was a good npm package for this, but there just isn't (that I could find).