mirror of
https://github.com/supabase/supabase.git
synced 2026-10-15 22:29:11 +03:00
## Context When signing up a new account on the dashboard, the dashboard's the one making the request to create a new profile for the user (ideally not, but the proper fix on the BE is currently blocked). We do so by making an initial request to GET `/profile`, and if it returns a 404, it's implied that the account doesn't exist and we fire `createProfile` Because of this, a race condition could exist (due to replica lag for example): - GET `/profile` returns 404, treat user as new - POST `/profile` returns 200 - Profile query is still in "error" state (`isError` is `true), and post sign-in tries to redirect to the new org page which triggers the `useEfect` [here](https://github.com/supabase/supabase/blob/master/apps/studio/lib/profile.tsx#L82-L96) - Which prompts another POST `/profile`, and it returns a 409 because the account's already created - This then keeps going in a loop which keeps calling `createProfile` and we didn't have a way to handle this, leading to users in a stuck loading state until the browser's refreshed ## Changes involved - Opt to invalidate the profile, permissions, and organizations if the user runs into a 409 - This should refresh the profile and we'll no longer be stuck in a create loop since `isError` should no longer be `true` then - Tighten the dependency array for where `createProfile` is triggered - Add exponential backoff up to 3 times for profile creation for transient failures (5xx, network, 429) - Never retry profile creation for 409, since there's no point doing so