dystcz / nuxt-sanctum-auth

Nuxt 3 + laravel sanctum authentication
134 stars 25 forks source link

Use JWT token instead of cookie for managing auth #7

Closed davide-granello closed 1 year ago

davide-granello commented 1 year ago

Hello, i'm testing authentication with nuxt3 using this package. After successful login, router is redirecting to /account, which has auth middleware with:

definePageMeta({
  middleware: 'auth'
})

Entering the page triggers user fetch, but my Laravel backend responds with 401 because apparently the request does not include authorization header with JWT bearer token.

Is it possible to use this package with token authentication method or only sanctum cookies?

My config:

routeRules: {
    '/account': { ssr: false },
    '/login': { ssr: false }
  },
  nuxtSanctumAuth: {
    baseUrl: 'http://unogmall.test/',
    endpoints: {
      csrf: '/sanctum/csrf-cookie',
      login: '/api/login',
      logout: '/api/logout',
      user: '/api/user'
    },
    redirects: {
      home: '/',
      login: '/login',
      logout: '/logout'
    }
  },
kreejzak commented 1 year ago

Hi @davide-granello ,

our package only supports Sanctum cookies for authentication at the moment, and unfortunately, we do not have any plans to add support for token authentication.

I would suggest you take a look at nuxt-alt/auth, this package may help you.

Kind regards