Files
supabase/apps/docs/lib/userAuth.ts
Ivan Vasilov 3e8baa2236 chore: Disable sending the Lock error to Sentry (#39999)
Disable sending the Lock error to Sentry.
2025-10-30 10:22:20 +01:00

37 lines
676 B
TypeScript

import { gotrueClient } from 'common'
import { useEffect } from 'react'
export const auth = gotrueClient
export async function getAccessToken() {
// ignore if server-side
if (typeof window === 'undefined') {
return
}
const {
data: { session },
error,
} = await auth.getSession()
if (error) {
throw error
}
return session?.access_token
}
export function useOnLogout(callback: () => void) {
useEffect(() => {
const {
data: {
subscription: { unsubscribe },
},
} = auth.onAuthStateChange((event) => {
if (event === 'SIGNED_OUT') {
callback()
}
})
return unsubscribe
}, [callback])
}