PM-7392 - Per PR feedback, REFRESH_ACCESS_TOKEN_ERROR_CALLBACK can be completely sync. + Refactor to method in main.background.

This commit is contained in:
Jared Snider 2024-05-13 14:09:27 -04:00
parent d79faadfa8
commit 4ded9e85ac
No known key found for this signature in database
GPG Key ID: A149DDD612516286
4 changed files with 13 additions and 13 deletions

View File

@ -376,6 +376,15 @@ export default class MainBackground {
const logoutCallback = async (logoutReason: LogoutReason, userId?: UserId) =>
await this.logout(logoutReason, userId);
const refreshAccessTokenErrorCallback = () => {
// Send toast to popup
this.messagingService.send("showToast", {
type: "error",
title: this.i18nService.t("errorRefreshingAccessToken"),
message: this.i18nService.t("errorRefreshingAccessTokenDesc"),
});
};
this.logService = new ConsoleLogService(false);
this.cryptoFunctionService = new WebCryptoFunctionService(self);
this.keyGenerationService = new KeyGenerationService(this.cryptoFunctionService);
@ -589,15 +598,7 @@ export default class MainBackground {
this.environmentService,
this.appIdService,
this.stateService,
() => {
// Send toast to popup
this.messagingService.send("showToast", {
type: "error",
title: this.i18nService.t("errorRefreshingAccessToken"),
message: this.i18nService.t("errorRefreshingAccessTokenDesc"),
});
return Promise.resolve();
},
refreshAccessTokenErrorCallback,
this.logService,
(logoutReason: LogoutReason, userId?: UserId) => this.logout(logoutReason, userId),
);

View File

@ -53,6 +53,6 @@ export const INTRAPROCESS_MESSAGING_SUBJECT = new SafeInjectionToken<Subject<Mes
);
export const CLIENT_TYPE = new SafeInjectionToken<ClientType>("CLIENT_TYPE");
export const REFRESH_ACCESS_TOKEN_ERROR_CALLBACK = new SafeInjectionToken<() => Promise<void>>(
export const REFRESH_ACCESS_TOKEN_ERROR_CALLBACK = new SafeInjectionToken<() => void>(
"REFRESH_ACCESS_TOKEN_ERROR_CALLBACK",
);

View File

@ -581,7 +581,6 @@ const safeProviders: SafeProvider[] = [
title: i18nService.t("errorRefreshingAccessToken"),
message: i18nService.t("errorRefreshingAccessTokenDesc"),
});
return Promise.resolve();
},
deps: [ToastService, I18nServiceAbstraction],
}),

View File

@ -160,7 +160,7 @@ export class ApiService implements ApiServiceAbstraction {
private environmentService: EnvironmentService,
private appIdService: AppIdService,
private stateService: StateService,
private refreshAccessTokenErrorCallback: () => Promise<void>,
private refreshAccessTokenErrorCallback: () => void,
private logService: LogService,
private logoutCallback: (logoutReason: LogoutReason) => Promise<void>,
private customUserAgent: string = null,
@ -1719,7 +1719,7 @@ export class ApiService implements ApiServiceAbstraction {
return this.doApiTokenRefresh();
}
await this.refreshAccessTokenErrorCallback();
this.refreshAccessTokenErrorCallback();
throw new Error("Cannot refresh access token, no refresh token or api keys are stored.");
}