manchenkoff / nuxt-auth-sanctum

Nuxt module for Laravel Sanctum authentication
https://manchenkoff.gitbook.io/nuxt-auth-sanctum/
MIT License
173 stars 21 forks source link

'manifest-route-rule' middleware already exists at '/node_modules/nuxt/dist/app/middleware/manifest-route-rule.js' #241

Open Jonston opened 2 hours ago

Jonston commented 2 hours ago

Greetings. Installed your package. Everything works fine, but the console shows an error 'manifest-route-rule' middleware already exists at /node_modules/nuxt/dist/app/middleware/manifest-route-rule.js'. I fixed it with a tweak

    router: {
        middleware: {
            override: true, // 
        },
    },

But I'm not sure if this is a good idea. Can you help me to fixed it?

manchenkoff commented 2 hours ago

Hi @Jonston, not sure how this is related to the module. I couldn't reproduce it on a fresh install. The error seems to be coming from a different place. Have you tried to investigate it?

Although it might not be related to the package, in order to let me help, I would need more details about your environment and the setup you are using and at which point you have this error. All these details are in Bug Report issue template.

Jonston commented 1 hour ago

The error occurs when following nuxt-link links. I just installed nuxt, vutify and your package.

// nuxt.config.ts
import {defineNuxtConfig} from 'nuxt/config';

export default defineNuxtConfig({
    modules: ['vuetify-nuxt-module', 'nuxt-auth-sanctum'],

    router: {
        middleware: {
            override: true, // Устанавливаем переопределение middleware
        },
    },

    vuetify: {
        moduleOptions: {
            // параметры модуля
        },
        vuetifyOptions: {
            // параметры Vuetify
        }
    },

    sanctum: {
        baseUrl: 'http://localhost:80',
        endpoints: {
            login: '/api/login',
            logout: '/api/logout',
        },
    },

    compatibilityDate: '2024-11-24'
})

package.json

{
  "name": "nuxt-app",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
  },
  "dependencies": {
    "nuxt": "^3.14.1592",
    "nuxt-auth-sanctum": "^0.5.2",
    "vue": "latest",
    "vue-router": "latest",
    "vuetify-nuxt-module": "^0.18.3"
  }
}

login.vue

<template>
  <v-sheet class="mx-auto" width="300">
    <v-form fast-fail @submit.prevent="submit">
      <v-text-field
          v-model="email"
          :rules="rules"
          label="Email"
      ></v-text-field>

      <v-text-field
          v-model="password"
          type="password"
          :rules="rules"
          label="Password"
      ></v-text-field>

      <v-btn class="mt-2" type="submit" block>Submit</v-btn>
    </v-form>
  </v-sheet>
</template>

<script setup lang="ts">
const { login } = useSanctumAuth();

const email = ref('user@test.com');
const password = ref('password');

const rules = [
  (v: string) => !!v || 'Required',
];

const submit = async () => {
  await login({
    email: email.value,
    password: password.value,
  });
}
</script>

<style scoped>

</style>

index.vue

<script setup lang="ts">
definePageMeta({
  middleware: ['sanctum:auth'],
});

const { logout } = useSanctumAuth();
const router = useRouter();

const submit = async () => {
  await logout();

  await router.push('/login');
}
</script>

<template>
  <div>
    <h1>Home Page</h1>
    <nuxt-link to="/about">About</nuxt-link>
    <br />
    <v-btn
        @click="submit"
        color="error"
    >
      logout
    </v-btn>
  </div>
</template>
Jonston commented 1 hour ago

I found the reason that triggers this error. When there is some kind of syntax or other error in the code, this notation appears. After the error is corrected, Nax begins to reinitialize the applications. It probably caches modules somehow. This is my guess. Can you reproduce it yourself?