2020-08-05 15:39:16 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
2020-12-16 16:06:14 +01:00
|
|
|
import { Storage } from '@ionic/storage';
|
2020-12-21 16:37:44 +01:00
|
|
|
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 {
|
2020-12-21 16:37:44 +01:00
|
|
|
user: any = "Max";
|
|
|
|
|
storageKey = "user";
|
2020-12-16 16:06:14 +01:00
|
|
|
constructor(private storage: Storage) {}
|
2020-08-06 14:31:07 +01:00
|
|
|
|
2020-12-21 16:37:44 +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
|
|
|
}
|
2020-12-16 16:06:14 +01:00
|
|
|
|
2020-12-21 16:37:44 +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-12-21 16:37:44 +01:00
|
|
|
|
2020-08-06 14:31:07 +01:00
|
|
|
|
2020-12-16 16:06:14 +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() {
|
2020-12-16 16:06:14 +01:00
|
|
|
await this.storage.clear();
|
|
|
|
|
}
|
2020-08-05 15:39:16 +01:00
|
|
|
}
|