mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
**feat:** adds a component to display API endpoints and anon keys in docs if user is authenticated makes the getting started UX smoother so users don't have to jump back and forth between docs and trying to find their keys in dashboard **out of scope:** it would be very cool to display these directly in the code blocks. I looked into it and it would require quite a bit of work forking and modifying code-hike, so out of scope for now Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
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])
|
|
}
|