Getting a Nuxt `WARN` while defining local middleware for pages protection
Environment
- Operating System:
Darwin - Node Version:
v18.18.2 - Nuxt Version:
3.12.3 - CLI Version:
3.12.0 - Nitro Version:
2.9.7 - Package Manager:
[email protected] - Builder:
- - User Config:
ssr,app,css,runtimeConfig,modules,apiParty,auth,plugins,components,build,devServer,compatibilityDate - Runtime Modules:
[email protected],@sidebase/[email protected] - Build Modules:
-
Reproduction
Disable global middleware and add those lines in the setup script of the Vue page :
definePageMeta({
middleware: 'auth'
})
Describe the bug
I have multiple times this two WARN in my terminal since I have installed and set up @sidebase/nuxt-auth, every time I save a Vue file :
WARN 'auth' middleware already exists at '/Users/Maxime/Desktop/Projets_de_code/yogi-dream.fr/frontend/node_modules/@sidebase/nuxt-auth/dist/runtime/middleware/auth.mjs'. You can set override: true to replace it.
WARN 'manifest-route-rule' middleware already exists at '/Users/Maxime/Desktop/Projets_de_code/yogi-dream.fr/frontend/node_modules/nuxt/dist/app/middleware/manifest-route-rule.js'. You can set override: true to replace it.
I am using the local middleware, and defining it this way :
definePageMeta({
middleware: 'auth'
})
Additional context
No response
Logs
No response
me too same warning about 'manifest-route-rule'
Can you share a bit more details about your setup? Ideally, providing a reproduction using stackblitz
Hello 👋
Please provide a reproduction for this issue 🙏
How can I create a reproduction?
Please use one of the following links to reproduce your issue.
- https://stackblitz.com/github/nuxt/starter/tree/v3-stackblitz
- https://codesandbox.io/s/github/nuxt/starter/v3-codesandbox
Please ensure that the reproduction is as minimal as possible. This will allow us to isolate the issue as best as possible.
Here are some more amazing posts about the importance of reproductions:
Hi @phoenix-ru, First of all, I am not very comfortable with "coding" with online tools. But I tried to reproduce the issue. To begin, I tried with a fake API like dummyjson.com, and there was a weird behaviour with disconnecting... After, I tried with the same backend as mine (which is Strapi), but couldn't start with Stackblitz...
So, the only thing I can tell you is that I am using a Strapi backend, with this @sidebase/nuxt-auth configuration :
auth: {
globalAppMiddleware: false,
baseURL: process.env.BACKEND_URL + "/api/",
provider: {
type: "local",
endpoints: {
signOut: false,
signIn: { path: "auth/local", method: "post" },
signUp: { path: "auth/local/register", method: "post" },
getSession: { path: "users/me", method: "get" },
},
token: {
signInResponseTokenPointer: "/jwt",
type: "Bearer",
cookieName: "auth.token",
headerName: "Authorization",
maxAgeInSeconds: 30 * 24 * 3600,
sameSiteAttribute: "lax",
httpOnlyCookieAttribute: false,
},
pages: {
login: "/auth/login",
},
},
},
And on every page I put this, I have the same number of a set of two WARN :
definePageMeta({
middleware: 'auth'
})
Thanks for your help!
Hi @maximehamou , thanks for the minimal example! You can also create reproductions as GH repository - the only requirement for a repro is that it is public and we can actually run the code and reproduce the issue
Unfortunately, as we are a bit swarmed with other work at the moment, I have to lower the priority of it a bit - but it is always encouraged to investigate yourself and propose fixes. Thanks for the understanding :slightly_smiling_face:
Hi @maximehamou 👋
I took a few minutes and tried to reproduce your error, but was sadly unsuccessful. Feel free to fork my branch and see if you can manage to reproduce the error in my minimal setup.
https://github.com/zoey-kaiser/nuxt-auth-reproductions/tree/892/investigate-middleware-warning
the filename of the middleware seems to matter.
this produces the warning
middleware/auth.ts
this doesnt
middleware/auth.custom.ts
This makes more sense! Even if our middleware is disabled, it still gets loaded into the Nuxt App. Therefore you cannot use the name naming as our auth middleware.
However, I think that we should rename our middleware to sidebase-auth, as this would resolve any potenial conflicts and I assume no-one will call with middlware sidebase-auth!