Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHAT-1650] Add user, application level token revoke helpers and iat claim in tokens #674

Merged
merged 11 commits into from
May 21, 2021
35 changes: 13 additions & 22 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,15 +638,7 @@ export class StreamChat<
return await this.patch<APIResponse>(this.baseURL + '/app', options);
}

_tokenRevokeEmptyStringError = () =>
new Error(
"Don't pass blank string for since, use null instead if resetting the token revoke",
);

/**
* Revokes all tokens on application level issued before given time
*/
async revokeTokens(before?: Date | string | null) {
_revokeTokensCheckDate = (before: Date | string | null | undefined): string | null => {
AnatolyRugalev marked this conversation as resolved.
Show resolved Hide resolved
if (before === undefined) {
before = new Date().toISOString();
}
Expand All @@ -656,11 +648,20 @@ export class StreamChat<
}

if (before === '') {
throw this._tokenRevokeEmptyStringError();
throw new Error(
"Don't pass blank string for since, use null instead if resetting the token revoke",
);
}

return before;
};

/**
* Revokes all tokens on application level issued before given time
*/
async revokeTokens(before?: Date | string | null) {
return await this.updateAppSettings({
revoke_tokens_issued_before: before,
revoke_tokens_issued_before: this._revokeTokensCheckDate(before),
});
}

Expand All @@ -675,17 +676,7 @@ export class StreamChat<
* Revokes tokens for a list of users issued before given time
*/
async revokeUsersToken(userIDs: string[], before?: Date | string | null) {
if (before === undefined) {
before = new Date().toISOString();
}

if (before instanceof Date) {
before = before.toISOString();
}

if (before === '') {
throw this._tokenRevokeEmptyStringError();
}
before = this._revokeTokensCheckDate(before);

const users: PartialUserUpdate<UserType>[] = [];
for (const userID of userIDs) {
Expand Down