You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
454 B
JavaScript

import { useEffect, useState } from 'preact/hooks'
export const useUser = () => {
const [user, setUser] = useState(null)
const logout = () => {
setUser(null)
}
useEffect(async () => {
const res = await fetch(`/api/current-user`, {
credentials: 'include',
})
if (res.ok) {
const user = await res.json()
setUser(user)
}
}, [])
return [user, logout]
}