sidebase / nuxt-auth

Authentication built for Nuxt 3! Easily add authentication via OAuth providers, credentials or Email Magic URLs!
https://auth.sidebase.io
MIT License
1.29k stars 164 forks source link

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

Open maximehamou opened 2 months ago

maximehamou commented 2 months ago

Environment

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

casatwy commented 1 month ago

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

phoenix-ru commented 1 month ago

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

github-actions[bot] commented 1 month ago

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: - [The Importance of Reproductions](https://antfu.me/posts/why-reproductions-are-required) - [How to Generate a Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/minimal-reproducible-example)
maximehamou commented 1 month ago

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 commented 1 month ago

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:

zoey-kaiser commented 1 month ago

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