Skip to content

Commit

Permalink
fix: ID-3129 Prevent Unknown or invalid refresh token requests from b…
Browse files Browse the repository at this point in the history
…eing triggered multiple times (#2479)
  • Loading branch information
imx-mikhala authored Dec 19, 2024
1 parent 8ea903d commit 284740a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/passport/sdk/src/authManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ describe('AuthManager', () => {

await expect(() => authManager.getUser()).rejects.toThrow(
new PassportError(
'Failed to refresh token: oops',
'Failed to refresh token: oops: Failed to remove user: this.userManager.removeUser is not a function',
PassportErrorType.AUTHENTICATION_ERROR,
),
);
Expand Down
17 changes: 15 additions & 2 deletions packages/passport/sdk/src/authManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,18 +481,31 @@ export default class AuthManager {
} catch (err) {
let passportErrorType = PassportErrorType.AUTHENTICATION_ERROR;
let errorMessage = 'Failed to refresh token';
let removeUser = true;

if (err instanceof ErrorTimeout) {
passportErrorType = PassportErrorType.SILENT_LOGIN_ERROR;
errorMessage = `${errorMessage}: ${err.message}`;
removeUser = false;
} else if (err instanceof ErrorResponse) {
passportErrorType = PassportErrorType.NOT_LOGGED_IN_ERROR;
errorMessage = `${err.message}: ${err.error_description}`;
errorMessage = `${errorMessage}: ${err.message || err.error_description}`;
} else if (err instanceof Error) {
errorMessage = err.message;
errorMessage = `${errorMessage}: ${err.message}`;
} else if (typeof err === 'string') {
errorMessage = `${errorMessage}: ${err}`;
}

if (removeUser) {
try {
await this.userManager.removeUser();
} catch (removeUserError) {
if (removeUserError instanceof Error) {
errorMessage = `${errorMessage}: Failed to remove user: ${removeUserError.message}`;
}
}
}

reject(new PassportError(errorMessage, passportErrorType));
} finally {
this.refreshingPromise = null; // Reset the promise after completion
Expand Down

0 comments on commit 284740a

Please sign in to comment.