mirror of
https://github.com/supabase/supabase.git
synced 2026-10-14 13:49:09 +03:00
* chore: toast auth initialization errors * Redirect back to sign in if authentication fails * add debug logs * remove debug logs * debug gotrue * remove gotrue debug
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { useQueryClient } from '@tanstack/react-query'
|
|
import {
|
|
AuthProvider as AuthProviderInternal,
|
|
clearLocalStorage,
|
|
gotrueClient,
|
|
useAuthError,
|
|
} from 'common'
|
|
import { PropsWithChildren, useCallback, useEffect } from 'react'
|
|
import { toast } from 'sonner'
|
|
|
|
import { GOTRUE_ERRORS, IS_PLATFORM } from './constants'
|
|
|
|
const AuthErrorToaster = ({ children }: PropsWithChildren) => {
|
|
const error = useAuthError()
|
|
|
|
useEffect(() => {
|
|
if (error !== null) {
|
|
// Check for unverified GitHub users after a GitHub sign in
|
|
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'
|
|
)
|
|
return
|
|
}
|
|
|
|
toast.error(error.message)
|
|
}
|
|
}, [error])
|
|
|
|
return children
|
|
}
|
|
|
|
export const AuthProvider = ({ children }: PropsWithChildren) => {
|
|
return (
|
|
<AuthProviderInternal alwaysLoggedIn={!IS_PLATFORM}>
|
|
<AuthErrorToaster>{children}</AuthErrorToaster>
|
|
</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])
|
|
}
|