mirror of
https://github.com/supabase/supabase.git
synced 2026-05-07 01:10:15 -04:00
3e8baa2236
Disable sending the Lock error to Sentry.
37 lines
676 B
TypeScript
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])
|
|
}
|