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-08-05 15:39:16 +01:00
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
2020-08-06 14:31:07 +01:00
|
|
|
})
|
|
|
|
|
export class StorageService {
|
2020-12-16 16:06:14 +01:00
|
|
|
constructor(private storage: Storage) {}
|
2020-08-06 14:31:07 +01:00
|
|
|
|
2020-12-16 16:06:14 +01:00
|
|
|
// Store the value
|
|
|
|
|
async store(value: any) {
|
2020-08-06 14:31:07 +01:00
|
|
|
const encryptedValue = btoa(escape(JSON.stringify(value)));
|
2020-12-16 16:06:14 +01:00
|
|
|
await this.storage.set('user', encryptedValue);;
|
2020-08-06 14:31:07 +01:00
|
|
|
}
|
2020-08-05 15:39:16 +01:00
|
|
|
|
2020-08-06 14:31:07 +01:00
|
|
|
// Get the value
|
2020-12-16 16:17:22 +01:00
|
|
|
async get() {
|
2020-12-16 16:06:14 +01:00
|
|
|
const ret = await this.storage.get('user').then(res=>{
|
|
|
|
|
return JSON.parse(unescape(atob(ret.value)));
|
|
|
|
|
});
|
|
|
|
|
|
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
|
|
|
}
|