Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting a Nuxt WARN while defining local middleware for pages protection #892

Closed
maximehamou opened this issue Aug 29, 2024 · 8 comments · Fixed by #957
Closed

Getting a Nuxt WARN while defining local middleware for pages protection #892

maximehamou opened this issue Aug 29, 2024 · 8 comments · Fixed by #957
Labels
bug A bug that needs to be resolved needs-investigation An issue where futhur investigation is required

Comments

@maximehamou
Copy link
Contributor

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

@maximehamou maximehamou added bug A bug that needs to be resolved pending An issue waiting for triage labels Aug 29, 2024
@casatwy
Copy link

casatwy commented Sep 5, 2024

me too
same warning about 'manifest-route-rule'

@phoenix-ru
Copy link
Collaborator

Can you share a bit more details about your setup? Ideally, providing a reproduction using stackblitz

@phoenix-ru phoenix-ru added needs-reproduction Action needed: A valid reproduction of the issue needs to be added and removed pending An issue waiting for triage labels Sep 5, 2024
Copy link

github-actions bot commented Sep 5, 2024

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.

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:

@maximehamou
Copy link
Contributor Author

maximehamou commented Sep 5, 2024

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!

@phoenix-ru phoenix-ru added needs-investigation An issue where futhur investigation is required and removed needs-reproduction Action needed: A valid reproduction of the issue needs to be added labels Sep 12, 2024
@phoenix-ru
Copy link
Collaborator

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 🙂

@zoey-kaiser
Copy link
Member

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

@busla
Copy link

busla commented Dec 10, 2024

the filename of the middleware seems to matter.

this produces the warning

middleware/auth.ts

this doesnt

middleware/auth.custom.ts

@zoey-kaiser
Copy link
Member

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug that needs to be resolved needs-investigation An issue where futhur investigation is required
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants