1
0
mirror of synced 2025-12-23 11:54:18 -05:00
Files
docs/components/hooks/useSession.ts
Kevin Heis ca61b3465a Use color_mode for gating "sign up" button (#29901)
* Use color_mode for gating "sign up" button

* Update useHasAccount.ts

* Update useHasAccount.ts

* Update useHasAccount.ts
2022-08-12 18:18:58 +00:00

28 lines
566 B
TypeScript

import { useEffect } from 'react'
import useSWR from 'swr'
export default async function fetcher<JSON = any>(
input: RequestInfo,
init?: RequestInit
): Promise<JSON> {
const res = await fetch(input, init)
return res.json()
}
export type Session = {
csrfToken?: string
}
// React hook version
export function useSession() {
const { data: session, error } = useSWR<Session>('/api/session', fetcher)
useEffect(() => {
if (error) {
console.warn('An error occurred loading the user session', error)
}
}, [error])
return { session }
}