mirror of
https://github.com/supabase/supabase.git
synced 2026-09-09 19:42:46 +08:00
Add `useSiwcQueryParamOptIn`, which flips on the ChatGPT sign-in rollout localStorage flag when `?siwc-enabled=1` is present, and call it from both pages/sign-in.tsx and pages/sign-up.tsx. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added support for enabling the sign-in experience via `?siwc-enabled=1`, automatically updating the stored opt-in flag on both sign-in and sign-up pages. * **Tests** * Added coverage confirming the stored flag is updated only for `siwc-enabled=1`, and not for missing, non-`1`, `0`, or repeated/array values. * Added assertions that the behavior is triggered consistently when rendering the sign-in and sign-up pages. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com> Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
28 lines
1005 B
TypeScript
28 lines
1005 B
TypeScript
import { LOCAL_STORAGE_KEYS, useParams } from 'common'
|
|
import { useEffect } from 'react'
|
|
|
|
import { useLocalStorageQuery } from './useLocalStorage'
|
|
|
|
/**
|
|
* Lets a shareable link (e.g. `/sign-in?siwc-enabled=1`) flip on the manual ChatGPT sign-in
|
|
* rollout switch (`LOCAL_STORAGE_KEYS.SIGN_IN_CHATGPT_ENABLED`, read by
|
|
* `useEnabledIdentityProviders`) for this browser, instead of requiring a devtools localStorage
|
|
* edit. Only ever meaningful on `/sign-in` and `/sign-up`, where this param would be linked to.
|
|
*
|
|
* Only the exact string `'1'` opts in; the flag is never cleared based on the param's absence, so
|
|
* it persists once set.
|
|
*/
|
|
export function useSiwcQueryParamOptIn() {
|
|
const { siwcEnabled } = useParams()
|
|
const [, setChatgptLocalStorageEnabled] = useLocalStorageQuery(
|
|
LOCAL_STORAGE_KEYS.SIGN_IN_CHATGPT_ENABLED,
|
|
false
|
|
)
|
|
|
|
useEffect(() => {
|
|
if (siwcEnabled === '1') {
|
|
setChatgptLocalStorageEnabled(true)
|
|
}
|
|
}, [siwcEnabled, setChatgptLocalStorageEnabled])
|
|
}
|