Files
doneit-web/src/app/services/storage.service.ts
T

38 lines
904 B
TypeScript
Raw Normal View History

2020-08-05 15:39:16 +01:00
import { Injectable } from '@angular/core';
import { Storage } from '@ionic/storage';
import { AuthConnstants } from '../config/auth-constants';
2020-08-05 15:39:16 +01:00
@Injectable({
providedIn: 'root'
2020-08-06 14:31:07 +01:00
})
export class StorageService {
user: any = "Max";
storageKey = "user";
constructor(private storage: Storage) {}
2020-08-06 14:31:07 +01:00
// set a key/value2
store(user:any){
const encryptedValue = btoa(escape(JSON.stringify(user)));
this.storage.set(AuthConnstants.AUTH, encryptedValue);
2020-08-06 14:31:07 +01:00
}
// Or to get a key/value pair
get(key:any){
let user = this.storage.get(key).then((val) => {
console.log(JSON.parse(unescape(atob(val))).data);
return JSON.parse(unescape(atob(val))).data;
});
return user;
2020-08-06 14:31:07 +01:00
}
2020-08-06 14:31:07 +01:00
/* async removeStorageItem(storageKey: string) {
await this.storage.remove({ key: storageKey });
} */
2020-08-05 15:39:16 +01:00
2020-08-06 14:31:07 +01:00
// Clear storage
async clear() {
await this.storage.clear();
}
2020-08-05 15:39:16 +01:00
}