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

**URL:** <https://community.auth0.com/t/next-js-lose-useuser-data-after-refresh-a-page-which-contains-data-of-user/90324>\
**Category:** Get Help\
**Tags:** user, nextjs, login, auth0\
**Created:** [September 9, 2022, 2:29pm UTC](https://community.auth0.com/t/next-js-lose-useuser-data-after-refresh-a-page-which-contains-data-of-user/90324 "2022-09-09T14:29:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![njudev](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/njudev/32/33316_2.png) [@njudev](https://community.auth0.com/u/njudev)\
**Post date:** [September 9, 2022, 2:29pm UTC](https://community.auth0.com/t/next-js-lose-useuser-data-after-refresh-a-page-which-contains-data-of-user/90324/1 "2022-09-09T14:29:47Z")

</div>

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

```auto
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’)

 ![image](https://global.discourse-cdn.com/auth0/original/3X/0/4/0468e0fcb36904b90560c223c973562983174e80.png)

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![njudev](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/njudev/32/33316_2.png) [@njudev](https://community.auth0.com/u/njudev)\
**Post date:** [September 9, 2022, 2:31pm UTC](https://community.auth0.com/t/next-js-lose-useuser-data-after-refresh-a-page-which-contains-data-of-user/90324/2 "2022-09-09T14:31:39Z")

</div>

> [@njudev](#):
>
> `[...auth].ts`

I mean `[...auth0].ts`

---

<div class="post-metadata">

**Author:** ![alex.brett](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alex.brett/32/60157_2.png) [@alex.brett](https://community.auth0.com/u/alex.brett)\
**Post date:** [December 11, 2024, 9:35pm UTC](https://community.auth0.com/t/next-js-lose-useuser-data-after-refresh-a-page-which-contains-data-of-user/90324/3 "2024-12-11T21:35:22Z")

</div>

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.

[https://community.auth0.com/t/why-is-authentication-lost-after-refreshing-my-single-page-application/56276](https://community.auth0.com/t/why-is-authentication-lost-after-refreshing-my-single-page-application/56276)

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

Best,  
Alex

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [December 25, 2024, 9:36pm UTC](https://community.auth0.com/t/next-js-lose-useuser-data-after-refresh-a-page-which-contains-data-of-user/90324/4 "2024-12-25T21:36:14Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
