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

fix: ID-3129 Prevent Unknown or invalid refresh token requests from being triggered multiple times #2479

Merged
merged 6 commits into from
Dec 19, 2024
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading