mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 16:23:44 +00:00
make logout callback async
This commit is contained in:
@@ -20,7 +20,6 @@ export abstract class ApiService {
|
|||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
identityBaseUrl: string;
|
identityBaseUrl: string;
|
||||||
deviceType: string;
|
deviceType: string;
|
||||||
logoutCallback: Function;
|
|
||||||
|
|
||||||
setUrls: (urls: EnvironmentUrls) => void;
|
setUrls: (urls: EnvironmentUrls) => void;
|
||||||
postIdentityToken: (request: TokenRequest) => Promise<IdentityTokenResponse | IdentityTwoFactorResponse>;
|
postIdentityToken: (request: TokenRequest) => Promise<IdentityTokenResponse | IdentityTwoFactorResponse>;
|
||||||
|
|||||||
@@ -27,11 +27,9 @@ export class ApiService implements ApiServiceAbstraction {
|
|||||||
baseUrl: string;
|
baseUrl: string;
|
||||||
identityBaseUrl: string;
|
identityBaseUrl: string;
|
||||||
deviceType: string;
|
deviceType: string;
|
||||||
logoutCallback: Function;
|
|
||||||
|
|
||||||
constructor(private tokenService: TokenService, private platformUtilsService: PlatformUtilsService,
|
constructor(private tokenService: TokenService, private platformUtilsService: PlatformUtilsService,
|
||||||
logoutCallback: Function) {
|
private logoutCallback: (expired: boolean) => Promise<void>) {
|
||||||
this.logoutCallback = logoutCallback;
|
|
||||||
this.deviceType = platformUtilsService.getDevice().toString();
|
this.deviceType = platformUtilsService.getDevice().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,7 +423,7 @@ export class ApiService implements ApiServiceAbstraction {
|
|||||||
|
|
||||||
private async handleError(response: Response, tokenError: boolean): Promise<ErrorResponse> {
|
private async handleError(response: Response, tokenError: boolean): Promise<ErrorResponse> {
|
||||||
if ((tokenError && response.status === 400) || response.status === 401 || response.status === 403) {
|
if ((tokenError && response.status === 400) || response.status === 401 || response.status === 403) {
|
||||||
this.logoutCallback(true);
|
await this.logoutCallback(true);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { TokenService } from '../abstractions/token.service';
|
|||||||
|
|
||||||
export class NodeApiService extends ApiService {
|
export class NodeApiService extends ApiService {
|
||||||
constructor(tokenService: TokenService, platformUtilsService: PlatformUtilsService,
|
constructor(tokenService: TokenService, platformUtilsService: PlatformUtilsService,
|
||||||
logoutCallback: Function) {
|
logoutCallback: (expired: boolean) => Promise<void>) {
|
||||||
super(tokenService, platformUtilsService, logoutCallback);
|
super(tokenService, platformUtilsService, logoutCallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export class SyncService implements SyncServiceAbstraction {
|
|||||||
private settingsService: SettingsService, private folderService: FolderService,
|
private settingsService: SettingsService, private folderService: FolderService,
|
||||||
private cipherService: CipherService, private cryptoService: CryptoService,
|
private cipherService: CipherService, private cryptoService: CryptoService,
|
||||||
private collectionService: CollectionService, private storageService: StorageService,
|
private collectionService: CollectionService, private storageService: StorageService,
|
||||||
private messagingService: MessagingService, private logoutCallback: Function) {
|
private messagingService: MessagingService, private logoutCallback: (expired: boolean) => Promise<void>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getLastSync(): Promise<Date> {
|
async getLastSync(): Promise<Date> {
|
||||||
@@ -134,7 +134,7 @@ export class SyncService implements SyncServiceAbstraction {
|
|||||||
const stamp = await this.userService.getSecurityStamp();
|
const stamp = await this.userService.getSecurityStamp();
|
||||||
if (stamp != null && stamp !== response.securityStamp) {
|
if (stamp != null && stamp !== response.securityStamp) {
|
||||||
if (this.logoutCallback != null) {
|
if (this.logoutCallback != null) {
|
||||||
this.logoutCallback(true);
|
await this.logoutCallback(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error('Stamp has changed');
|
throw new Error('Stamp has changed');
|
||||||
|
|||||||
Reference in New Issue
Block a user