nuxt-alt / auth

An alternative module to @nuxtjs/auth
https://nuxt-alt-auth.vercel.app/
MIT License
94 stars 20 forks source link

Next middleware continues processing even after auth middleware's redirect #118

Open croro613 opened 2 weeks ago

croro613 commented 2 weeks ago

Environment

Nuxt Config

auth: {
    rewriteRedirects: false,
    watchLoggedIn: true,
    resetOnResponseError: true,
    redirect: {
      logout: logoutPath,
      login: loginPath,
      home: "/",
      callback: callBackPath,
    },
    stores: {
      cookie: {
        enabled: true,
        prefix: "auth.",
      },
    },
    strategies: {
      local: {
        name: "local",
        scheme: "~/auth/schemes/customLocalScheme",
        token: {
          property: "token",
          global: true,
          required: true,
          type: "Bearer",
        },
        user: {
          property: "data",
        },
        endpoints: {
          login: { url: loginUrl, method: "post" },
          user: { url: userUrl, method: "get" },
        },
      },
    },
  },

Reproduction

https://stackblitz.com/edit/nuxt-starter-4cwdoi?file=pages%2Ftest.vue

Describe the bug

I define multiple middleware (including auth) on a page, as written in the provided link. Currently, when a user is not authenticated, the auth middleware redirects them to the login page. However, at the same time, the next middleware is also executed.

I think that it would be better if the next middleware were skipped when redirected by auth. In fact, if we use navigateTo, the next middleware is skipped. The Nuxt community also recommends using navigateTo.

However, with PR #79, it seems navigateTo is no longer usable when redirected. Is there a problem with using this?

Additional context

No response

Logs

No response