storj/web/satellite/src/utils/localData.ts
Egon Elbre f5ac00f909 web/satellite: switch to eslint, sass, bump deps
tslint has been deprecated so it's nice to switch to eslint.
Currently this uses a minimal eslint, to get things up and running.

node-sass requires C which does not work nicely on all platforms.

Change-Id: I3ca9adf2971475c009e541652b7637c18ad960f4
2021-08-03 15:56:33 +00:00

64 lines
1.8 KiB
TypeScript

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
/**
* LocalData exposes methods to manage local storage.
*/
export class LocalData {
private static userId = 'userId';
private static selectedProjectId = 'selectedProjectId';
private static userIdPassSalt = 'userIdPassSalt';
public static getUserId(): string | null {
return localStorage.getItem(LocalData.userId);
}
public static setUserId(id: string): void {
localStorage.setItem(LocalData.userId, id);
}
public static removeUserId(): void {
localStorage.removeItem(LocalData.userId);
}
public static getSelectedProjectId(): string | null {
return localStorage.getItem(LocalData.selectedProjectId);
}
public static setSelectedProjectId(id: string): void {
localStorage.setItem(LocalData.selectedProjectId, id);
}
public static removeSelectedProjectId(): void {
localStorage.removeItem(LocalData.selectedProjectId);
}
public static getUserIDPassSalt(): UserIDPassSalt | null {
const data: string | null = localStorage.getItem(LocalData.userIdPassSalt);
if (data) {
const parsed = JSON.parse(data);
return new UserIDPassSalt(parsed.userId, parsed.passwordHash, parsed.salt);
}
return null;
}
public static setUserIDPassSalt(id: string, passwordHash: string, salt: string): void {
const data = new UserIDPassSalt(id, passwordHash, salt);
localStorage.setItem(LocalData.userIdPassSalt, JSON.stringify(data));
}
}
/**
* UserIDPassSalt is an entity holding user id, password hash and salt to be stored in local storage.
*/
export class UserIDPassSalt {
public constructor(
public userId: string = '',
public passwordHash: string = '',
public salt: string = '',
) {}
}