# Expired access token with lock and checkSession not working to keep user logged in

**URL:** <https://community.auth0.com/t/expired-access-token-with-lock-and-checksession-not-working-to-keep-user-logged-in/17707>\
**Category:** Get Help\
**Tags:** checksession, lock\
**Created:** [November 8, 2018, 11:56am UTC](https://community.auth0.com/t/expired-access-token-with-lock-and-checksession-not-working-to-keep-user-logged-in/17707 "2018-11-08T11:56:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shanif](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/shanif/32/9596_2.png) [@shanif](https://community.auth0.com/u/shanif)\
**Post date:** [November 8, 2018, 11:56am UTC](https://community.auth0.com/t/expired-access-token-with-lock-and-checksession-not-working-to-keep-user-logged-in/17707/1 "2018-11-08T11:56:07Z")

</div>

Hi there, thanks for taking the time to read this. Our startup just started implementing an Auth0 login to incorporate logging in with social accounts. We’re using the lock API and we’re also storing some data for each of our users in the user\_metadata field.

Unfortunately, it seems like after a user has left the site for more than two hours, we can’t access their user\_metadata. We did try to incorporate the checkSession code that’s suggested, however it doesn’t seem to be working and is throwing the following error:

```auto
attributes: {error: "Expired token received for JSON Web Token validation"}
error: "Unauthorized"
message: "Expired token received for JSON Web Token validation"
statusCode: 401

```

The code we’re using is:

```auto
this.authenticationLock.checkSession({}, function(error, authResult) {
      if (error || !authResult) {
        this.authenticationLock.show();
      }
      else {
        request(options, function (error, response, body) {
          if (error) throw new Error(error);
          try {
              if (body !== null && JSON.parse(body).user_metadata !== undefined) {
                  // do stuff with response here
              }
          }
          catch (e) {
          }
        });
      }
    });

```

Are we doing something wrong?

Thanks for the help!

---

<div class="post-metadata">

**Author:** ![nicolas\_sabena](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nicolas_sabena/32/6064_2.png) [@nicolas\_sabena](https://community.auth0.com/u/nicolas_sabena)\
**Post date:** [November 12, 2018, 12:46am UTC](https://community.auth0.com/t/expired-access-token-with-lock-and-checksession-not-working-to-keep-user-logged-in/17707/2 "2018-11-12T00:46:51Z")

</div>

Hi Shanif. When you say:

> we can’t access their user\_metadata

what exactly do you mean by that? Are you talking about an HTTP request? If so, to what endpoint? And what error are you getting?

As for the `Expired token received for JSON Web Token validation` error, is this caused by the `checkSession()` method? Can you record and attach a [HAR file](https://auth0.com/docs/har) so that I can understand where the error is coming from? Make sure to delete any passwords in the .HAR file before attaching.

---

<div class="post-metadata">

**Author:** ![shanif](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/shanif/32/9596_2.png) [@shanif](https://community.auth0.com/u/shanif)\
**Post date:** [November 12, 2018, 12:08pm UTC](https://community.auth0.com/t/expired-access-token-with-lock-and-checksession-not-working-to-keep-user-logged-in/17707/3 "2018-11-12T12:08:49Z")

</div>

Hi Nicolas,

Thanks for getting back to me. It turns out I was able to fix this by taking the response from the `checkSession` method and saving the various fields (id\_token, access\_token, etc) back into the user’s local storage. After I did that and then made an HTTP request to the endpoint to retrieve users (I believe it was /users/) things started working.

Thanks!

---

<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 12, 2018, 12:08pm UTC](https://community.auth0.com/t/expired-access-token-with-lock-and-checksession-not-working-to-keep-user-logged-in/17707/4 "2018-12-12T12:08:49Z")

</div>

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