#Nuxt Supabase Login is loading forever

1 messages · Page 1 of 1 (latest)

wicked crater
#

I dont really know if this is a question for supabase or nuxt but i am using both.

When i login my nuxt app should redirect via middleware when the user is authenticated. Additionally i have some router.push functions and a location.reload function to move the user over to the dashboard. but sometimes it just loads forever and does not redirect the user unless a manual page reload happens

this is my login function, triggered by a button klick if the user has given his email and password

const signInEmail = async () => {
    try {
        loading.value = true
        const { error } = await client.auth.signInWithPassword({
            email: email.value,
            password: password.value,
        })
        toast.add({ title: 'Welcome', description: 'You have successfully signed in' })
        router.push(localePath("/app"))
        location.reload();
        loading.value = false
    }
    catch (error) {
        toast.add({ title: 'Error', description: error.message, color: 'red' })
    } finally {

    }
}```
#

Nuxt Supabase Login is loading forever

cyan rapids
# wicked crater I dont really know if this is a question for supabase or nuxt but i am using bot...

hey @wicked crater! You shouldn't need to reload your window like you're doing. My supabase impl looks fairly similar with a couple of differences.
You can simply router.push with the string of the path, but this is an async function which is probably why nothing is happening for you right now.

async function signIn() {
    loading.value = true
    const { data, error } = await supabase.auth.signInWithPassword({
        email: email.value,
        password: password.value
    })
    if (error) {
        toastStore.addToast(error.message, 'error')
        errorMsg.value = error.message
    } else await router.push('/dashboard')

    loading.value = false
}
wicked crater
#

Oh okay, i did not know that router push is async. It also does not throw any errors.

I will try that and tell you if it solved my problem ☺️

cyan rapids