nuxt-auth icon indicating copy to clipboard operation
nuxt-auth copied to clipboard

Auth status unexpectedly unauthenticated when using globalAppMiddleware

Open bodgerbarnett opened this issue 9 months ago • 0 comments

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


bodgerbarnett avatar Apr 13 '25 18:04 bodgerbarnett