Files
supabase/apps/docs/features/auth/auth.client.tsx
T
Alaister YoungandCharis Lam 6d732a2a4b chore: remove auth-helpers (deprecated) (#32541)
* chore: remove auth-helpers (deprecated)

* type supabase client in feedback

* small adjustments to error and loading state handling for docs search

---------

Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
2025-01-06 18:08:44 +08:00

39 lines
897 B
TypeScript

'use client'
import { useQueryClient } from '@tanstack/react-query'
import { AuthProvider } from 'common'
import { type PropsWithChildren, useCallback } from 'react'
import { LOCAL_STORAGE_KEYS, remove } from '~/lib/storage'
import { useOnLogout } from '~/lib/userAuth'
/**
*
* !!! IMPORTANT !!!
* Ensure data is cleared on sign out.
*
*/
const SignOutHandler = ({ children }: PropsWithChildren) => {
const queryClient = useQueryClient()
const cleanUp = useCallback(() => {
queryClient.cancelQueries()
queryClient.clear()
Object.keys(LOCAL_STORAGE_KEYS).forEach((key) => {
remove('local', LOCAL_STORAGE_KEYS[key])
})
}, [queryClient])
useOnLogout(cleanUp)
return <>{children}</>
}
const AuthContainer = ({ children }: PropsWithChildren) => (
<AuthProvider>
<SignOutHandler>{children}</SignOutHandler>
</AuthProvider>
)
export { AuthContainer }