https://supabase.com/ logo
#help
Title
# help
m

Mattyfaz

05/17/2022, 7:08 AM
Using the
@nuxtjs/supabase
module, trying to setup a really basic auth. On my login page I have:
Copy code
javascript
const login = async () => {
  await auth
    .signIn({
      email: email.value,
      password: password.value,
    })
    .then(() => {
      router.push("/");
    })
    .catch((error) => {
      return alert(error);
    });
};
On the index page I have the following calling middleware:
Copy code
javascript
definePageMeta({
  middleware: "auth",
});
And the
auth
middleware is:
Copy code
javascript
export default defineNuxtRouteMiddleware((to, _from) => {
    const user = useSupabaseUser()
    if (!user.value) {
        console.log("User not authenticated")
        return navigateTo('/login')
    }
})
When I login, the middleware fails and says "User not authenticated". However it actually has, if I refresh I am logged in. It's almost like the middleware just acts too quickly and needs to wait a second. Any idea how to resolve this?
n

Needle

05/17/2022, 7:08 AM
Hello @Mattyfaz! 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.
Thread was archived by @Mattyfaz. Anyone can send a message to unarchive it.
Mattyfaz (2022-05-17)
m

Mattyfaz

05/17/2022, 7:34 AM
Solved by using
navigateTo("/")
rather than
router.push("/")
in the login page.
n

Needle

05/17/2022, 1:12 PM
Thread was archived by @Mattyfaz. Anyone can send a message to unarchive it.