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

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

32 lines
966 B
TypeScript
Raw Normal View History

2018-04-04 14:22:18 +02:00
import { AppIdService as AppIdServiceAbstraction } from "../abstractions/appId.service";
import { StorageService } from "../abstractions/storage.service";
import { HtmlStorageLocation } from "../enums/htmlStorageLocation";
2022-02-22 15:39:11 +01:00
import { Utils } from "../misc/utils";
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, {
htmlStorageLocation: HtmlStorageLocation.Local,
});
2018-01-09 22:19:55 +01:00
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();
await this.storageService.save(key, guid, {
htmlStorageLocation: HtmlStorageLocation.Local,
});
2018-01-09 22:19:55 +01:00
return guid;
2021-12-16 13:36:21 +01:00
}
2018-01-09 22:19:55 +01:00
}