# Authentication token expired

**URL:** <https://forum.social.plus/t/authentication-token-expired/1125>\
**Category:** Web\
**Created:** [February 15, 2024, 7:30am UTC](https://forum.social.plus/t/authentication-token-expired/1125 "2024-02-15T07:30:52Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![lorandd](https://avatars.discourse-cdn.com/v4/letter/l/ba9def/32.png) [@lorandd](https://forum.social.plus/u/lorandd)\
**Post date:** [February 15, 2024, 7:30am UTC](https://forum.social.plus/t/authentication-token-expired/1125/1 "2024-02-15T07:30:52Z")

</div>

Hello,

I’m using secure mode and using the UIKit for the chat. I have generated an authtoken with a server request which works, but after around 10 minutes I get a console error:

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/amity/original/1X/4b59b79a1b9d360591be5eb401f8bedd9ec31bf6.png)

I understand that I need to refresh the auth token and the UIKit doesn’t do this, but I don’t know where can I catch that the authtoken has expired.

I’m doing the login from my app with:

```auto

Client.login(
        {
          userId: userId,
          displayName: displayName,
          authToken: authToken,
        },
        amitySessionHandler

```

the amitySessionHandler → sessionWillRenewAccessToken is not called

I have tried to add a console log in UIKit login method to see if the `sessionWillRenewAccessToken` is called, but it is not

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/amity/original/1X/db3c721847f0b47481b01c6f7acb86f837e14f28.png)

Can you let me how and where should I do this?

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [February 15, 2024, 2:35pm UTC](https://forum.social.plus/t/authentication-token-expired/1125/2 "2024-02-15T14:35:39Z")

</div>

Hello @lorandd did you implement this part: [Session State - Amity Docs](https://docs.amity.co/amity-sdk/core-concepts/session-state#session-handler) ?

---

<div class="post-metadata">

**Author:** ![lorandd](https://avatars.discourse-cdn.com/v4/letter/l/ba9def/32.png) [@lorandd](https://forum.social.plus/u/lorandd)\
**Post date:** [February 15, 2024, 4:56pm UTC](https://forum.social.plus/t/authentication-token-expired/1125/3 "2024-02-15T16:56:23Z")

</div>

I think I did. I did it like this:

```auto
Client.login(
        {
          userId: userId,
          displayName: displayName,
          authToken: authToken,
        },
        amitySessionHandler
      )

```

```auto
 const amitySessionHandler: Amity.SessionHandler = {
    sessionWillRenewAccessToken(renewal: Amity.AccessTokenRenewal) {
      
      debugger;
      console.log("RENEW TOKEN");
      dispatch(getAmityAuthToken()).then((authToken) => {
        renewal.renewWithAuthToken(authToken);
      });
    },
  };

```

I also did this:

```auto
 useEffect(() => {
    return Client.onSessionStateChange((state: Amity.SessionStates) => {
      debugger;
      console.log("Session state changed: " + state);
    });
  }, []);

```

but those function are not called when the token expires

Is there anything else I need to do or do you see any issues with how I did it?

Thanks

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [February 16, 2024, 12:03pm UTC](https://forum.social.plus/t/authentication-token-expired/1125/4 "2024-02-16T12:03:08Z")

</div>

Hi @lorandd your implementation seems correct, our dev is investigating on this. Will keep you posted.

---

<div class="post-metadata">

**Author:** ![lorandd](https://avatars.discourse-cdn.com/v4/letter/l/ba9def/32.png) [@lorandd](https://forum.social.plus/u/lorandd)\
**Post date:** [February 23, 2024, 7:11am UTC](https://forum.social.plus/t/authentication-token-expired/1125/5 "2024-02-23T07:11:41Z")

</div>

Hey, is there any progress on this ? Thanks

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [February 23, 2024, 7:31am UTC](https://forum.social.plus/t/authentication-token-expired/1125/6 "2024-02-23T07:31:33Z")

</div>

Hello , As a workaround, we recommend updating the open-source code manually to include the following function for session renewal:

```auto
sessionWillRenewAccessToken(renewal) {
  // secure mode
  if (authToken) {
    renewal.renewWithAuthToken(authToken);
    return;
  }

  renewal.renew();
},

```

This fix will apply to both the SDK and UI Kit, and we plan to release a fix for the UI Kit early next week.

Thank you.

---

<div class="post-metadata">

**Author:** ![lorandd](https://avatars.discourse-cdn.com/v4/letter/l/ba9def/32.png) [@lorandd](https://forum.social.plus/u/lorandd)\
**Post date:** [February 23, 2024, 8:17pm UTC](https://forum.social.plus/t/authentication-token-expired/1125/7 "2024-02-23T20:17:40Z")

</div>

you mean here, right ?

> <https://github.com/AmityCo/Amity-Social-Cloud-UIKit-Web-OpenSource/blob/develop/src/core/providers/UiKitProvider/index.tsx#L100>

added like this:

```auto
sessionWillRenewAccessToken(renewal) {
            console.log('sessionWillRenewAccessToken');
            debugger;

            if (authToken) {
              renewal.renewWithAuthToken(authToken);
              return;
            }

            renewal.renew();
          },

```

but this is never called and the session still expires…

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [February 26, 2024, 1:10pm UTC](https://forum.social.plus/t/authentication-token-expired/1125/8 "2024-02-26T13:10:33Z")

</div>

I’ve informed the team to verify this, and we’ll get back to you with an update.

---

<div class="post-metadata">

**Author:** ![lorandd](https://avatars.discourse-cdn.com/v4/letter/l/ba9def/32.png) [@lorandd](https://forum.social.plus/u/lorandd)\
**Post date:** [February 28, 2024, 8:49am UTC](https://forum.social.plus/t/authentication-token-expired/1125/9 "2024-02-28T08:49:27Z")

</div>

I’ve noticed that there is a new version of the UIKit, v3.2.2 but this error persist is this version as well…

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [February 28, 2024, 8:56am UTC](https://forum.social.plus/t/authentication-token-expired/1125/10 "2024-02-28T08:56:39Z")

</div>

Hello @lorandd thank you for flagging this. Could you also confirm if this issue [Session issues on UI Kit 3.0? - #7 by amitysupport](https://forum.social.plus/t/session-issues-on-ui-kit-3-0/1071/7) has been solved in ver 3.2.2?

---

<div class="post-metadata">

**Author:** ![lorandd](https://avatars.discourse-cdn.com/v4/letter/l/ba9def/32.png) [@lorandd](https://forum.social.plus/u/lorandd)\
**Post date:** [February 28, 2024, 9:10am UTC](https://forum.social.plus/t/authentication-token-expired/1125/11 "2024-02-28T09:10:14Z")

</div>

no, the session issue still persist in this version as mentioned in my previous comment

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [February 28, 2024, 2:24pm UTC](https://forum.social.plus/t/authentication-token-expired/1125/12 "2024-02-28T14:24:36Z")

</div>

Thank you for confirming, @lorandd. When you mentioned that the issue still persists, is it accurate to say that the authentication token expires immediately, or does it expire after 10 minutes due to the renewAccessToken not being triggered?

---

<div class="post-metadata">

**Author:** ![lorandd](https://avatars.discourse-cdn.com/v4/letter/l/ba9def/32.png) [@lorandd](https://forum.social.plus/u/lorandd)\
**Post date:** [February 28, 2024, 5:15pm UTC](https://forum.social.plus/t/authentication-token-expired/1125/13 "2024-02-28T17:15:34Z")

</div>

It doesn’t seem to expiry immediately… I see a console error like in the image in the initial post that a token has expired, usually after a few minutes of inactivity… it could be 10 minutes as well… most likely because the renew is not called…

---

<div class="post-metadata">

**Author:** ![lorandd](https://avatars.discourse-cdn.com/v4/letter/l/ba9def/32.png) [@lorandd](https://forum.social.plus/u/lorandd)\
**Post date:** [February 29, 2024, 6:30am UTC](https://forum.social.plus/t/authentication-token-expired/1125/14 "2024-02-29T06:30:24Z")

</div>

sometimes it expires sooner then 10 minutes

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [February 29, 2024, 6:39am UTC](https://forum.social.plus/t/authentication-token-expired/1125/15 "2024-02-29T06:39:28Z")

</div>

@lorandd Thank you for the information. I have forwarded this to the team for further investigation, and I will update you again if there is any progress.

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [February 29, 2024, 8:15am UTC](https://forum.social.plus/t/authentication-token-expired/1125/16 "2024-02-29T08:15:53Z")

</div>

@lorandd Can I confirm that the Uikit itself calls the session API, which then throws an error without taking any further action ?

---

<div class="post-metadata">

**Author:** ![lorandd](https://avatars.discourse-cdn.com/v4/letter/l/ba9def/32.png) [@lorandd](https://forum.social.plus/u/lorandd)\
**Post date:** [February 29, 2024, 8:30am UTC](https://forum.social.plus/t/authentication-token-expired/1125/17 "2024-02-29T08:30:04Z")

</div>

Yes, we don’t explicitly call the session endpoint, this is called from the UIKit and then throws that error

---

<div class="post-metadata">

**Author:** ![SocialPlus\_Support](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.social.plus/socialplus_support/32/798_2.png) [@SocialPlus\_Support](https://forum.social.plus/u/SocialPlus_Support)\
**Post date:** [February 29, 2024, 8:45am UTC](https://forum.social.plus/t/authentication-token-expired/1125/18 "2024-02-29T08:45:43Z")

</div>

@lorandd Thank you for your response. I will pass this information on to my team.
