-
Notifications
You must be signed in to change notification settings - Fork 1
fix: auth race condition when using the SDK in the Studio structure #646
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
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub.
|
What's the best way to test this in the procurement studio? pnpm link? Afraid I'm still getting the 403 but could be on me |
The best way to test is to
|
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.
Nothing in the code sticks out as strange, but just reporting that I did get the 403 on first load (I think I did a login flow first). Refreshing / pressing retry did help. Not sure if that is the intended result.
I wasn't able to recreate by logging out of the dashboard and trying again, so it could also have been a case of staleness somewhere (I did get a 502 in one of my attempts to recreate 😬 )


- Changed the storage key logic to use a studio-specific key when studio mode is enabled. - Updated tests to reflect changes in storage key usage and ensure correct behavior in studio mode. - Improved test descriptions for clarity regarding studio mode conditions.
@cngonzalez I have made some changes and I'm pretty sure that I have resolved the race condition thoroughly now. |
Description
This PR improves Studio Mode authentication by using project-specific storage keys for tokens and properly handling authentication in Studio Mode contexts. It ensures that Studio Mode authentication works correctly by using the appropriate storage keys, bypassing organization verification, and using project hostnames for API requests when in Studio Mode.
What to review
subscribeToStateAndFetchCurrentUser.ts
where project hostname is now used when Studio Mode is enabledAuthBoundary.tsx
modifications that disable organization verification when in Studio ModeComlinkTokenRefreshProvider
that clarifies when token refresh is not neededTesting
The easiest way to test this is by using the code in the SDK movie procurement studio
https://github.com/sanity-io/sdk-movie-procurement-studio/blob/main/sanity.config.ts#L24
Tested the authentication flow with Studio Mode enabled and verified that:
Fun gif