nuxt-alt / auth

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

Cannot read properties of undefined (reading 'as') #61

Closed zerosdev closed 1 year ago

zerosdev commented 1 year ago

Environment

Nuxt Config

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
    runtimeConfig: {
        public: {
            appApiURL: process.env.APP_API_URL || 'http://localhost:8000',
            appURL: process.env.APP_URL || 'http://localhost:3000',
            businessURL: process.env.BUSINESS_URL || 'http://localhost:4000',
            assetURL: process.env.ASSET_URL || 'http://localhost:3000',
            frontURL: process.env.FRONT_URL || 'http://localhost:9000'
        }
    },
    modules: [
        '@nuxt-alt/auth',
        '@pinia/nuxt',
        '@nuxtjs/device',
        // '@nuxtjs/i18n',
        'bootstrap-vue-next/nuxt'
    ],
    build: {
        transpile: ['@vuepic/vue-datepicker']
    },
    device: {
        refreshOnResize: true
    },
    auth: {
        fullPathRedirect: true,
        globalMiddleware: true,
        strategies: {
            'laravelSanctum': {
                provider: 'laravel/sanctum',
                url: process.env.APP_API_URL || 'http://localhost:8000',
                endpoints: {
                    csrf: {
                        baseURL: process.env.APP_API_URL || 'http://localhost:8000',
                        url: '/sanctum/csrf-cookie',
                    },
                    login: {
                        baseURL: process.env.APP_API_URL || 'http://localhost:8000',
                        url: '/api/auth/login',
                    },
                    logout: {
                        baseURL: process.env.APP_API_URL || 'http://localhost:8000',
                        url: '/api/auth/logout',
                    },
                    user: {
                        baseURL: process.env.APP_API_URL || 'http://localhost:8000',
                        url: '/api/auth/user',
                        propertyName: '',
                    }
                },
                user: {
                    property: false,
                },
            },
        }
    },
})

Reproduction

Upgrade to Nuxt 3.6 with npx nuxi upgrade --force

Describe the bug

After upgrading to Nuxt 3.6, there an error as shown below

ERROR Cannot start nuxt: Cannot read properties of undefined (reading 'as') 20:28:43

at /C:/laragon/www/xxxxx/xxxx/node_modules/@nuxt-alt/auth/dist/module.mjs:200:31 at Array.filter () at setup (/C:/laragon/www/xxxxx/xxxx/node_modules/@nuxt-alt/auth/dist/module.mjs:199:57) at async normalizedModule (/C:/laragon/www/xxxxx/xxxx/node_modules/@nuxt/kit/dist/index.mjs:2140:17) at async installModule (/C:/laragon/www/xxxxx/xxxx/node_modules/@nuxt/kit/dist/index.mjs:2409:95) at async initNuxt (/C:/laragon/www/xxxxx/xxxx/node_modules/nuxt/dist/index.mjs:3174:7) at async load (/C:/laragon/www/xxxxx/xxxx/node_modules/nuxi/dist/chunks/dev.mjs:204:9)

Additional context

No response

Logs

No response

Aleksandr-Baranchuk commented 1 year ago

Same problem.

If you change the strategy to cookie, it will work. It seems to me that the providers are not loading.

farid-mkh commented 1 year ago

It appears that this error occurs when you haven't defined a scheme for the strategy:

auth: {
  strategies: {
    laravelSanctum: {
      scheme: 'local',
      .....
   }
Denoder commented 1 year ago

I cannot reproduce this error