This commit is contained in:
Peter Maquiran
2021-07-18 20:52:01 +01:00
parent f5e65c1477
commit 9e9f72da3e
2 changed files with 12 additions and 9 deletions
+2 -2
View File
@@ -32,8 +32,8 @@ export class AuthService {
this.headers = new HttpHeaders();
if (localstoreService.get('user', null) != null) {
this.ValidatedUser = localstoreService.get('user',{});
if (this.localstoreService.get('user', null) != null) {
this.ValidatedUser = this.localstoreService.get('user',{});
}
if (localStorage.getItem("userChat") != null) {
+10 -7
View File
@@ -10,9 +10,12 @@ export class LocalstoreService {
constructor() { }
getKey(keyName) {
return this.prefix + keyName
}
get( keyName, safe) {
keyName = this.prefix + keyName
keyName = this.getKey(keyName)
const ciphertext = localStorage.getItem(keyName)
@@ -21,18 +24,18 @@ export class LocalstoreService {
if(ciphertext) {
const bytes = AES.decrypt(ciphertext, hashKey)
var decryptedData = bytes.toString(enc.Utf8);
if(typeof(decryptedData) != 'string') {
decryptedData = JSON.parse(decryptedData)
try {
return JSON.parse(decryptedData)
} catch {
return decryptedData;
}
return decryptedData;
} else {
return safe;
}
}
set(keyName, value) {
keyName = this.prefix + keyName
keyName = this.getKey(keyName)
if(typeof(value) != 'string') {
value = JSON.stringify(value)