nuxt-community / auth-module

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

All features work fine under npm run dev, but when starting with npm run start, after logging in and fetching the user, the page cannot be refreshed. #1874

Closed jyoutetsu8387 closed 7 months ago

jyoutetsu8387 commented 7 months ago

Version

module: 5.0.0-1667386184.dfbbb54 nuxt: ^2.15.8

Nuxt configuration

mode:

Nuxt configuration

auth: {
    redirect: {
      login: '/',
      logout: '/login', // Redirect to home page after logout
      home: '/'
    },
    localStorage: true,
    strategies: {
      local: {
        scheme: 'refresh',
        user: {
          property: 'result',
          autoFetch: true
        },
        token: {
          property: 'token',
          global: true
        },
        refreshToken: {
          property: 'refreshToken',
          data: 'refreshToken',
          maxAge: 60 * 60 * 24 * 14,
          tokenRequired: false
        },
        endpoints: {
          // refresh: { url: '/auth/secure/refresh-token', method: 'post' },
          login: {
            url: '/auth/admin/login',
            method: 'post'
          },
          user: {
            url: '/auth/admin/user',
            method: 'get'
          },
          logout: false
        }
      }
    },
    watchLoggedIn: true
  },

Reproduction

this is my repository

https://github.com/jyoutetsu8387/seian-admin-fev2

What is expected?

i hope that after successful login, Click on Google Chrome to refresh the page The page can be refreshed successfully

What is actually happening?

In fact, when I'm running npm run dev, all functionalities and pages work perfectly. I can obtain tokens, user information, and so on from the backend.

All the code executes successfully without any exceptions. p1

However, when I start with npm run start, although I can still log in successfully and fetch user information, when I press the browser's refresh button, the screen freezes. When I open the browser's debug mode, I find that it gets stuck here (as shown in Figure 2). p2

Like in Figure 3, when I refresh the page, it keeps getting stuck there. Then, after about 10 seconds, it redirects to an error page. p3

Steps to reproduce

1.Run npm run build. 2.Run npm run start. 3.After successful login, the redirection is successful (up to this point everything is successful, I confirmed all JWT tokens, etc., in the cookie). 4.Pressing the refresh button causes the page to freeze.

Additional information

https://github.com/jyoutetsu8387/seian-admin-fev2

This issue only occurs after I log in. If I don't log in, all other APIs that don't require login work fine.

I've tried everything possible to solve it myself, but because there are no error messages, I feel frustrated and clueless. Since the project is already at the stage of going online, if this issue cannot be resolved, I feel like I'll never be able to go online. Also, starting a refactoring process at this point would be a huge undertaking.

I'm very grateful for anyone who can help me with this issue. Thank you very much.

jyoutetsu8387 commented 7 months ago

After recent testing, I found that This bug has nothing to do with nuxt-auth So close this issue