nuxt-community / auth-module

Zero-boilerplate authentication support for Nuxt 2
https://auth.nuxtjs.org
MIT License
1.93k stars 925 forks source link

Refresh tokens. v5. #1648

Closed cwe-dev closed 2 years ago

cwe-dev commented 2 years ago

Hi all. i have a problem with refresh tokens. i tried do local scheme \ laravel/jwt scheme and broke at enable refresh tokens.

"@nuxtjs/auth-next": "^5.0.0-1624817847.21691f1"

Task: Enable autorefresh token when access token is expired.

Scheme:

  auth: {
    strategies: {
      laravelJWT: {
        provider: 'laravel/jwt',
        url: 'https://api.site.ru/v1',
        endpoints: {
          login: { url: '/auth/login', method: 'post', propertyName: false },
          logout: { url: '/auth/logout', method: 'post', propertyName: false },
          refresh: { url: '/auth/refresh', method: 'post', propertyName: false },
          user: { url: '/auth/user', method: 'get', propertyName: false },
        },
        token: {
          property: 'access_token',
          maxAge: 60 * 60,
        },
        refreshToken: {
          maxAge: 20160 * 60,
        },
      },
    },
    redirect: {
      login: '/',
      home: '/account',
    },
  },

When access token is expired i haven't autorefresh and redirected to authorization page.

Also i tried manually request refreshTokens()method, handleRefresh() method. When i got new pair tokens, but when is first expiration time is gone - i unauthorized and redirected on login page. How can i manually change expiration date on tokens. I've tried setTokenand setUserToken, and Token.sync, but it didnt work, when the maxAge in nuxt.config.js is expired - i lost connection.

What do i do wrong. It seems to be working on auto mode via documentation, but not

jmformenti commented 2 years ago

I’m also not sure if I’m doing something wrong but I'm experimenting the same problem using version "@nuxtjs/auth-next": "^5.0.0-1643365392.dae6516".

When I manually call refreshTokens() (I would expect the method to be called automatically but not) is not sent because token expired but indeed is valid.

tobyreid commented 2 years ago

could it be related to - https://github.com/nuxt-community/auth-module/pull/1417