Skip to content

Auth status unexpectedly unauthenticated when using globalAppMiddleware #1013

@bodgerbarnett

Description

@bodgerbarnett

Environment

Reproduction

nuxt.config.ts

globalAppMiddleware: {
  isEnabled: false,
  addDefaultCallbackUrl: true,
}
custom-middleware.ts

export default defineNuxtRouteMiddleware(async (to) => {
    // logic to determine whether the logged-in user should have access to this page
    return abortNavigation()
}
page.vue

definePageMeta({
  middleware: ["sidebase-auth", "custom-middleware"]
})

Describe the bug

I need to use the object representation of globalAppMiddleware, as I need to add the default callback URL on login.

I also need some custom middleware that checks to see whether the logged-in user should have access to the page. If they don't, I want to abort the navigation and show an error page.

If I set globalAppMiddleware to false, it all works as expected.
But if I use the object representation, the sidebase-auth middleware sometimes returns "unauthenticated" as the user's status and that causes the user to be redirected to the login page before the custom middleware is able to abort and show the error. So the logged-in user is redirected to the login page.

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA bug that needs to be resolvedpendingAn issue waiting for triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions