mirror of
https://github.com/bitwarden/browser.git
synced 2024-10-19 07:35:48 +02:00
29 lines
842 B
TypeScript
29 lines
842 B
TypeScript
|
import { UtilsService } from './utils.service';
|
||
|
|
||
|
import { AppIdService as AppIdServiceInterface } from '../abstractions/appId.service';
|
||
|
import { StorageService } from '../abstractions/storage.service';
|
||
|
|
||
|
export class AppIdService implements AppIdServiceInterface {
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
const guid = UtilsService.newGuid();
|
||
|
await this.storageService.save(key, guid);
|
||
|
return guid;
|
||
|
}
|
||
|
}
|