trandaison / nuxt-3-auth

A simple authentication module for Nuxt 3
https://nuxt-3-auth.github.io
56 stars 5 forks source link

Error when trying to use the package in nuxt app #25

Closed enzortk closed 1 month ago

enzortk commented 1 month ago

I set the options in nuxt.config.ts like this

 auth: {
    endpoints: {
      baseUrl: process.env.NUXT_PUBLIC_API_BASE_URL,
      login: { url: 'auth/login', method: 'POST', property: 'data' },
      logout: { url: 'auth/logout', method: 'DELETE' },
      refresh: { url: 'auth/refresh-token', method: 'POST', property: 'data' },
      user: { url: 'auth/me', method: 'GET', property: 'data' },
      // signup: { url: 'auth/register' },
    },
    middleware: { global: true },
    token: {
      headerName: 'Authorization',
      type: 'Bearer',
    },
    refreshToken: {
      paramName: 'token',
    },
  },

but when I run the app, console shows this error

nuxt.js?v=a9160863:122 [nuxt] error caught during app initialization TypeError: Cannot read properties of undefined (reading 'hasTokens') at authMiddleware (auth.mjs?v=a9160863:19:28)

Seems the $auth object is undefined at that point of the code, any idea of what is wrong with the config ?

trandaison commented 1 month ago

@enzortk Can you create a reproduction repo on stackblitz.com?

enzortk commented 1 month ago

@enzortk Can you create a reproduction repo on stackblitz.com?

Ok! give me some time and I'll share the link