Next.js lose useUser() data after refresh a page which contains data of user

Hello, I’m new here. Started to exploring auth0 and I faced a problem when I refresh page where I got user declared with

const { user } = useUser();

and then everytime I refresh the page I lost my session (I don’t know) and then I can’t read values of: user.nickname

TypeError: Cannot read properties of undefined (reading ‘nickname’)

I turned on refresh token in my auth0 account and then write this in my [...auth].ts file:

import { handleAuth, handleLogin } from '@auth0/nextjs-auth0';

export default handleAuth({
  async login(req, res) {
    try {
      await handleLogin(req, res, {
        authorizationParams: {
          useRefreshTokens: true,
        },
      });
    } catch (error) {
      res.status(error.status || 500).end(error.message);
    }
  },
});

and it happens again. What I got to do to make it work?

I mean [...auth0].ts

Hey @njudev!

I noticed in the post you mentioned you lost the session when you refreshed the page. I found an article which can help troubleshoot this issue.

Please give this a read and see if this fixes the issue!

Best,
Alex