Hello,
I have an extension that needs to send a number, selected on click, to my EBS and with user ID.
Sometimes, for some users, the EBS fails to extract the Twitch ID from token because the latter is expired: TokenExpiredError: jwt expired
The extension was likely running for more than 1 hour at impacted users, but the extension is working for a vast majority of users that are on the stream for more than 1 hour. So I suspect that the token is sometimes not refreshed after expiration.
I have already read this post that describe the problem I could have, adjusted my code accordingly and still have issues.
I have also read this post, but I would like to insure my code is correct before to explore 3rd-party issues.
Here is my process:
- I’m subscribing to the onAuthorized event to trigger token refresh:
private constructor() {
this._twitchExtension = window["Twitch"]?.ext;
this._twitchExtension?.onAuthorized(this.handle_onAuthorized.bind(this));
}
- And then I store the authentication object into the _authentifier attribute:
public handle_onAuthorized(authentifier: any): void {
this._authentifier = authentifier;
// Only notify the first time for app start processings
this.triggerOnceAuthenticatedListeners();
}
- So, when I need to send the number user has selected to my EBS, I use the _authentifier object to get the token and include it into the request body:
public getPlayerToken(): string {
return this._authentifier.token;
}
Is there something wrong with this implementation ?