Skip to content

Possible race condition #552

@miguel-arrf

Description

@miguel-arrf

Hi!

I have the following structure:

  • a login page
  • a dashboard page (for signed in users)
  • an auth middleware (not global, and both pages are using it via the definePageMeta)

What's happening:

  1. I log in using the signInWithPassword. I await that call, and after it is completed and without errors I redirect the user to the dashboard page.
  2. The auth middleware was triggered, allowed the passage to the dashboard page since for the middleware the session (from useSupabaseSession) is valid (as expected).
  3. The dashboard page loads. I then have this (more or less, this is a reduced example):
<script setup lang="ts">
const user = useSupabaseUser()
onMounted(async () => {
    if (!user.value || !user.value.email) {
        console.error("no user!")
    }
})
</script>

Problem:
The user is not defined during the onMounted and I don't get why. If I reload the page, it works. If I await a bit before redirecting the page, it also works, but that seems rather inelegant.

Thank you for the help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions