Hi! I'm having issues redirecting from magic link ...
# help
r
Hi! I'm having issues redirecting from magic link signup to an "auth required page". The redirect happens even though the user has signed in/up successfully. Has anyone experienced this? I'm using the
useUser()
hook from
supabase-auth-helpers
n
Hello @reed! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
l
I know this thread is old, but just so if anyone in the future is looking for a solution, I found out that it is because
useUser()
has a loading sequence before it retrieves the user object.
Copy code
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.