Files
supabase/apps/studio/lib/auth.tsx
T
Francesco SansalvadoreandAlaister Young a4cfcd9b2e global user dropdown in docs and www (#35063)
* docs: user nav dropdown

* www: user dropdown nav

* update menus

* chore: add complete local storage allowlist

* move all local-storage to common

* reload after logOut

* add local storage key changes from #35175

* fix errors

* add more keys

* fix merge bugs

---------

Co-authored-by: Alaister Young <a@alaisteryoung.com>
2025-05-05 11:48:06 +02:00

40 lines
1.2 KiB
TypeScript

import { useQueryClient } from '@tanstack/react-query'
import { AuthProvider as AuthProviderInternal, clearLocalStorage, gotrueClient } from 'common'
import { PropsWithChildren, useCallback, useEffect } from 'react'
import { toast } from 'sonner'
import { GOTRUE_ERRORS, IS_PLATFORM } from './constants'
export const AuthProvider = ({ children }: PropsWithChildren<{}>) => {
// Check for unverified GitHub users after a GitHub sign in
useEffect(() => {
async function handleEmailVerificationError() {
const { error } = await gotrueClient.initialize()
if (error?.message === GOTRUE_ERRORS.UNVERIFIED_GITHUB_USER) {
toast.error(
'Please verify your email on GitHub first, then reach out to us at support@supabase.io to log into the dashboard'
)
}
}
handleEmailVerificationError()
}, [])
return <AuthProviderInternal alwaysLoggedIn={!IS_PLATFORM}>{children}</AuthProviderInternal>
}
export { useAuth, useIsLoggedIn, useSession, useUser } from 'common'
export function useSignOut() {
const queryClient = useQueryClient()
return useCallback(async () => {
const result = await gotrueClient.signOut()
clearLocalStorage()
await queryClient.clear()
return result
}, [queryClient])
}