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

refactor: initialize the user auth state synchronously #639

Merged
merged 1 commit into from
Mar 19, 2022

Conversation

petebacondarwin
Copy link
Contributor

We can now initialize the user state synchronously, which means that
we can remove the checks for whether it has been done or not in each
of the user auth functions.

@changeset-bot
Copy link

changeset-bot bot commented Mar 18, 2022

🦋 Changeset detected

Latest commit: c9db89e

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 18, 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/2009253485/npm-package-wrangler-639

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/639/npm-package-wrangler-639

Or you can use npx with this latest build directly:

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

@threepointone
Copy link
Contributor

Hope this isn't urgent, I'd love to review this before it lands

@petebacondarwin
Copy link
Contributor Author

No not urgent but it is not as scary as you may think.

Copy link
Contributor

@JacobMGEvans JacobMGEvans left a comment

Choose a reason for hiding this comment

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

Interesting! Since things are sync now, you can remove the throw checks and the entire mocking of users and directly test the functions handling the user, i.e. reinitialise, USER_AUTH_CONFIG_FILE, writeAuthConfigFile

Copy link
Contributor

@threepointone threepointone left a comment

Choose a reason for hiding this comment

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

Looks great! Don't forget to run it a couple of times locally before landing.

/**
* Compute the current auth state.
*/
function getAuthState(): State {
Copy link
Contributor

@threepointone threepointone Mar 19, 2022

Choose a reason for hiding this comment

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

"state" isn't super descriptive here. How about getAuthTokens()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would quite like to go a step further and split apart the OAuth state processing from the external auth token state. But I thought that would be too large a change in this PR.

The OAuth state fields that are stored in State really an internal implementation thing which code outside of user.tsx should not care about.

/**
* Run the initialisation of the auth state, in the case that something changed.
*/
export function reinitialise(): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you like to take this opportunity to rename this function too? It was never clear even before. Got any ideas?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah - I changed it from initialise() to reinitialise() but I would be up for an even more description name... perhaps reinitialiseAuth()?

We can now initialize the user state synchronously, which means that
we can remove the checks for whether it has been done or not in each
of the user auth functions.
@petebacondarwin petebacondarwin merged commit 5161e1e into cloudflare:main Mar 19, 2022
@petebacondarwin petebacondarwin deleted the sync-auth-init branch March 19, 2022 17:11
@github-actions github-actions bot mentioned this pull request Mar 19, 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.

3 participants