Mattyfaz
05/17/2022, 7:08 AM@nuxtjs/supabase
module, trying to setup a really basic auth.
On my login page I have:
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:
javascript
definePageMeta({
middleware: "auth",
});
And the auth
middleware is:
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?Needle
05/17/2022, 7:08 AMMattyfaz
05/17/2022, 7:34 AMnavigateTo("/")
rather than router.push("/")
in the login page.Needle
05/17/2022, 1:12 PM