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: trigger login flow if refreshtoken isn't valid #709

Merged
merged 1 commit into from
Mar 26, 2022

Conversation

threepointone
Copy link
Contributor

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).

@changeset-bot
Copy link

changeset-bot bot commented Mar 26, 2022

🦋 Changeset detected

Latest commit: e974c7b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
wrangler Patch

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

@github-actions
Copy link
Contributor

github-actions bot commented Mar 26, 2022

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 with this latest build directly:

npx https://prerelease-registry.developers.workers.dev/runs/2044856879/npm-package-wrangler-709 dev path/to/script.js

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On minor suggestion.

Comment on lines 867 to 876
const didRefresh = await refreshToken();
if (didRefresh) {
return true;
} else {
return isInteractive && (await login());
}
Copy link
Contributor

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...

Suggested change
const didRefresh = await refreshToken();
if (didRefresh) {
return true;
} else {
return isInteractive && (await login());
}
return await refreshToken() || isInteractive && (await login());

Copy link
Contributor Author

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
Copy link
Contributor

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
@threepointone threepointone force-pushed the login-on-refresh-fail branch from bad6374 to e974c7b Compare March 26, 2022 14:46
@threepointone threepointone merged commit 7e8ec9a into main Mar 26, 2022
@threepointone threepointone deleted the login-on-refresh-fail branch March 26, 2022 14:53
@github-actions github-actions bot mentioned this pull request Mar 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants