nuxt-alt / auth

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

Cannot set properties of undefined (setting 'refresh') #96

Closed toniengelhardt closed 6 months ago

toniengelhardt commented 6 months ago

Environment

Nuxt Config

import '@total-typescript/ts-reset'
import { sentryVitePlugin } from '@sentry/vite-plugin'
import { version } from './package.json'

export default defineNuxtConfig({
  ssr: false,
  runtimeConfig: {
    indexable: true,
  },
  modules: [
    '@nuxt/devtools',
    '@nuxt-alt/auth',
    '@nuxt-alt/http',
    '@nuxtjs/color-mode',
    '@nuxtjs/plausible',
    '@nuxtseo/module',
    '@pinia/nuxt',
    '@pinia-plugin-persistedstate/nuxt',
    '@unocss/nuxt',
    '@vueuse/nuxt',
    'nuxt-icon',
  ],
  imports: {
    dirs: [
      './stores',
    ],
  },
  experimental: {
    headNext: true,
  },
  sourcemap: {
    server: process.env.NODE_ENV !== 'test',
    client: process.env.NODE_ENV !== 'test',
  },
  devtools: {
    enabled: false,
  },
  app: {
    head: {
      htmlAttrs: {
        lang: 'en',
        translate: 'no', // Avoid translation.
      },
      link: [
        { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
        { rel: 'icon', type: 'image/svg+xml', href: '/icon.svg' },
      ],
    },
  },
  vite: {
    build: {
      sourcemap: true,
    },
    plugins: [
      // Sentry Vite plugin needs to be after all other plugins.
      sentryVitePlugin({
        authToken: process.env.SENTRY_AUTH_TOKEN,
        org: 'promptmetheus',
        project: 'archery',
        release: {
          name: version,
        },
        telemetry: false,
      }),
    ],
  },
  typescript: {
    shim: false,
  },
  css: [
    'vue-toastification/dist/index.css',
    'assets/postcss/style.postcss',
  ],
  postcss: {
    plugins: {
      'cssnano': false,
      'postcss-nested': {},
    },
  },
  nitro: {
    routeRules: {
      '/*': { prerender: false }, // Note: for some reason / is prerendered by default, which breaks the auth middleware.
    },
    prerender: {
      crawlLinks: false, // Note: SEO Kit is setting this to true.
    },
  },
  piniaPersistedstate: {
    storage: 'localStorage',
  },
  http: {
    baseURL: process.env.API_URL,
    browserBaseURL: process.env.API_URL,
  },
  auth: {
    globalMiddleware: true,
    redirectStrategy: 'query', // IMPORTANT! Otherwise, there will be an infinite logout loop.
    watchLoggedIn: true,
    cookie: {
      prefix: 'auth.',
      options: {
        path: '/',
        secure: process.env.NODE_ENV === 'production', // Enable only in production.
        sameSite: 'lax', // IMPORTANT!
      },
    },
    redirect: {
      login: '/login',
      logout: '/login',
      callback: '/login',
      home: '/',
    },
    strategies: {
      local: {
        scheme: 'refresh',
        token: {
          property: 'access',
          type: 'JWT',
        },
        refreshToken: {
          property: 'refresh',
          data: 'refresh', // IMPORTANT! Note that the refresh token is not a JWT token.
        },
        user: {
          property: false,
        },
        endpoints: {
          login: {
            url: `${process.env.API_URL}/auth/token/`,
            method: 'post',
          },
          refresh: {
            url: `${process.env.API_URL}/auth/token/refresh/`,
            method: 'post',
          },
          user: false,
          logout: {
            url: `${process.env.API_URL}/auth/logout/`,
            method: 'post',
          },
        },
      },
      google: {
        clientId: process.env.GOOGLE_CLIENT_ID,
        responseType: 'code',
        codeChallengeMethod: '', // This is important!
        endpoints: {
          scope: 'openid profile email',
          token: `${process.env.API_URL}/auth/social/google/`,
          userInfo: `${process.env.API_URL}/users/me/`,
        },
        token: {
          // The token type needs to match the AUTH_HEADER_TYPES setting under
          // SIMPLE_JWT in the Django settings (Bearer by default).
          type: 'JWT',
          property: 'access',
        },
        refreshToken: {
          // The refresh token is not a JWT token!
          property: 'refresh',
        },
      },
    },
  },
  colorMode: {
    classSuffix: '',
  },
  schemaOrg: {
    enabled: false,
  },
  ogImage: {
    enabled: false,
  },
  sitemap: {
    include: [
      '/',
      '/register',
      '/login',
      '/reset-password',
    ],
  },
})

Reproduction

Cannot reproduce locally, but suddenly getting a lot of these errors in production. I think it came in with @nuxt-alt/auth 3.1.1/3.1.2, but not sure, maybe earlier. Did anything change in the config?

Describe the bug

Screenshot 2024-01-05 at 11 55 18

Additional context

No response

Logs

No response

Denoder commented 6 months ago

update the auth module

toniengelhardt commented 6 months ago

Thanks a lot for the super fast fix 🙏🏽

Will test and report back.

toniengelhardt commented 6 months ago

I think it is resolved.