diff --git a/src/client.ts b/src/client.ts index d9c0c5885..2695df347 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1237,6 +1237,10 @@ export class StreamChat(this.baseURL + `/messages/${id}/commit`); } + + /** + * Calls the token provider to retrieve a new token + * + * This is an internal method, you only need to use it if, for some reason, the existing refresh logic of the client doesn't suit your needs. + * + */ + async refreshToken() { + const token = await this.tokenManager.loadToken(); + return this.wsConnection?.refreshToken(token); + } } diff --git a/src/connection.ts b/src/connection.ts index d567bdb56..1c1fc0618 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -622,4 +622,10 @@ export class StableWSConnection { + // you can expect `token.ack` event if backend registered the new token for the WS connection + const d = JSON.stringify({ type: 'token.refresh', api_key: this.client.key, token }); + this.ws?.send(d); + }; } diff --git a/src/events.ts b/src/events.ts index a895adb63..9c91967ab 100644 --- a/src/events.ts +++ b/src/events.ts @@ -42,6 +42,8 @@ export const EVENT_MAP = { 'user.updated': true, 'user.watching.start': true, 'user.watching.stop': true, + 'token.expiring': true, + 'token.ack': true, // local events 'channels.queried': true,