mirror of
https://github.com/supabase/supabase.git
synced 2026-10-13 05:09:12 +03:00
When user logs out from the user dropdown, they're redirected to the sign-in page via the withAuth redirect, which means that the returnTo param is used -- but if the user _intentionally_ logged out, this might not be the right behavior, i.e., if they want to log in to another account. Instead, if they chose to log out, we shouldn't use the returnTo param. Since the /logout page already implements this behavior, I changed "Log out" button to just route to the /logout page.
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import { useQueryClient } from '@tanstack/react-query'
|
|
import { PropsWithChildren, useCallback, useEffect } from 'react'
|
|
import { toast } from 'sonner'
|
|
|
|
import {
|
|
AuthProvider as AuthProviderInternal,
|
|
clearLocalStorage,
|
|
gotrueClient,
|
|
useAuthError,
|
|
} from 'common'
|
|
import { useAiAssistantStateSnapshot } from 'state/ai-assistant-state'
|
|
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 function useSignOut() {
|
|
const queryClient = useQueryClient()
|
|
const { clearStorage: clearAssistantStorage } = useAiAssistantStateSnapshot()
|
|
|
|
return useCallback(async () => {
|
|
const result = await gotrueClient.signOut()
|
|
clearLocalStorage()
|
|
// Clear Assistant IndexedDB
|
|
await clearAssistantStorage()
|
|
queryClient.clear()
|
|
|
|
return result
|
|
}, [queryClient, clearAssistantStorage])
|
|
}
|