Skip to content

Instantly share code, notes, and snippets.

@IgorHalfeld
Last active September 25, 2024 18:50
Show Gist options
  • Save IgorHalfeld/fb3be54851e043657ba827ca4b17cd54 to your computer and use it in GitHub Desktop.
Save IgorHalfeld/fb3be54851e043657ba827ca4b17cd54 to your computer and use it in GitHub Desktop.
import { useEffect, useState } from 'react'
export const useCurrentUser () {
const [user, setCurrentUser] = useState()
const [error, setError] = useState<Error>()
const [loading, setLoading] = useState<boolean>(false)
const fetchLoggedUser = async () => {
setLoading(true)
const { data: { user }, error } = await client.auth.getUser()
if (error) {
setError(error)
}
setCurrentUser(user)
setLoading(false)
}
useEffect(() => {
fetchLoggedUser()
}, [])
return {
user,
error,
loading
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment