reed
06/01/2022, 7:03 PMuseUser()
hook from supabase-auth-helpers
Needle
06/01/2022, 7:03 PMlulzsun
08/16/2022, 4:45 AMuseUser()
has a loading sequence before it retrieves the user object.
js
const { user, isLoading } = useUser();
useEffect(() => {
// wait until loading stopped
if(!isLoading) {
// if user does not exist, redirect to login page
if (!user) {
router.push('/login');
}
else {
// do stuff if user is logged in
}
}
}, [isLoading, user])
I don't know if this is the best solution, but it worked in my case.