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(); this.headers = new HttpHeaders();
if (localstoreService.get('user', null) != null) { if (this.localstoreService.get('user', null) != null) {
this.ValidatedUser = localstoreService.get('user',{}); this.ValidatedUser = this.localstoreService.get('user',{});
} }
if (localStorage.getItem("userChat") != null) { if (localStorage.getItem("userChat") != null) {
+10 -7
View File
@@ -10,9 +10,12 @@ export class LocalstoreService {
constructor() { } constructor() { }
getKey(keyName) {
return this.prefix + keyName
}
get( keyName, safe) { get( keyName, safe) {
keyName = this.prefix + keyName keyName = this.getKey(keyName)
const ciphertext = localStorage.getItem(keyName) const ciphertext = localStorage.getItem(keyName)
@@ -21,18 +24,18 @@ export class LocalstoreService {
if(ciphertext) { if(ciphertext) {
const bytes = AES.decrypt(ciphertext, hashKey) const bytes = AES.decrypt(ciphertext, hashKey)
var decryptedData = bytes.toString(enc.Utf8); var decryptedData = bytes.toString(enc.Utf8);
if(typeof(decryptedData) != 'string') { try {
decryptedData = JSON.parse(decryptedData) return JSON.parse(decryptedData)
} } catch {
return decryptedData; return decryptedData;
} else { }
return safe;
} }
} }
set(keyName, value) { set(keyName, value) {
keyName = this.prefix + keyName keyName = this.getKey(keyName)
if(typeof(value) != 'string') { if(typeof(value) != 'string') {
value = JSON.stringify(value) value = JSON.stringify(value)