bitwarden-estensione-browser/common/src/services/appId.service.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

28 lines
773 B
TypeScript
Raw Normal View History

2018-04-23 19:03:47 +02:00
import { Utils } from "../misc/utils";
2018-01-09 22:19:55 +01:00
2018-04-04 14:22:18 +02:00
import { AppIdService as AppIdServiceAbstraction } from "../abstractions/appId.service";
import { StorageService } from "../abstractions/storage.service";
2018-01-09 22:19:55 +01:00
2018-04-04 14:22:18 +02:00
export class AppIdService implements AppIdServiceAbstraction {
2018-01-09 22:19:55 +01:00
constructor(private storageService: StorageService) {}
getAppId(): Promise<string> {
return this.makeAndGetAppId("appId");
}
getAnonymousAppId(): Promise<string> {
return this.makeAndGetAppId("anonymousAppId");
}
private async makeAndGetAppId(key: string) {
const existingId = await this.storageService.get<string>(key);
if (existingId != null) {
return existingId;
}
2021-12-16 13:36:21 +01:00
2018-04-23 19:03:47 +02:00
const guid = Utils.newGuid();
2018-01-09 22:19:55 +01:00
await this.storageService.save(key, guid);
return guid;
2021-12-16 13:36:21 +01:00
}
2018-01-09 22:19:55 +01:00
}