lorandd
February 15, 2024, 7:30am
1
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:
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:
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
Can you let me how and where should I do this?
Hello @lorandd did you implement this part: Session State - Amity Docs ?
lorandd
February 15, 2024, 4:56pm
3
I think I did. I did it like this:
Client.login(
{
userId: userId,
displayName: displayName,
authToken: authToken,
},
amitySessionHandler
)
const amitySessionHandler: Amity.SessionHandler = {
sessionWillRenewAccessToken(renewal: Amity.AccessTokenRenewal) {
debugger;
console.log("RENEW TOKEN");
dispatch(getAmityAuthToken()).then((authToken) => {
renewal.renewWithAuthToken(authToken);
});
},
};
I also did this:
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
Hi @lorandd your implementation seems correct, our dev is investigating on this. Will keep you posted.
lorandd
February 23, 2024, 7:11am
5
Hey, is there any progress on this ? Thanks
Hello , As a workaround, we recommend updating the open-source code manually to include the following function for session renewal:
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.
lorandd
February 23, 2024, 8:17pm
7
you mean here, right ?
);
setClient(ascClient);
}
const currentIsConnected = ASCClient.isConnected();
if (!currentIsConnected) {
await ASCClient.login(
{ userId, displayName },
{
sessionWillRenewAccessToken(renewal) {
renewal.renew();
},
},
);
}
setIsConnected(true);
if (stateChangeRef.current == null) {
stateChangeRef.current = ASCClient.onSessionStateChange((state) => {
added like this:
sessionWillRenewAccessToken(renewal) {
console.log('sessionWillRenewAccessToken');
debugger;
if (authToken) {
renewal.renewWithAuthToken(authToken);
return;
}
renewal.renew();
},
but this is never called and the session still expires…
1 Like
I’ve informed the team to verify this, and we’ll get back to you with an update.
lorandd
February 28, 2024, 8:49am
9
I’ve noticed that there is a new version of the UIKit, v3.2.2 but this error persist is this version as well…
Hello @lorandd thank you for flagging this. Could you also confirm if this issue Session issues on UI Kit 3.0? - #7 by amitysupport has been solved in ver 3.2.2?
lorandd
February 28, 2024, 9:10am
11
no, the session issue still persist in this version as mentioned in my previous comment
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?
lorandd
February 28, 2024, 5:15pm
13
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…
lorandd
February 29, 2024, 6:30am
14
sometimes it expires sooner then 10 minutes
@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.
@lorandd Can I confirm that the Uikit itself calls the session API, which then throws an error without taking any further action ?
lorandd
February 29, 2024, 8:30am
17
Yes, we don’t explicitly call the session endpoint, this is called from the UIKit and then throws that error
@lorandd Thank you for your response. I will pass this information on to my team.