mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
improvements
This commit is contained in:
@@ -1,37 +1,33 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Storage } from '@ionic/storage';
|
||||
import { AuthConnstants } from '../config/auth-constants';
|
||||
import { Plugins } from '@capacitor/core';
|
||||
const { Storage } = Plugins;
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class StorageService {
|
||||
user: any = "Max";
|
||||
storageKey = "user";
|
||||
constructor(private storage: Storage) {}
|
||||
constructor() {}
|
||||
|
||||
// set a key/value2
|
||||
store(user:any){
|
||||
const encryptedValue = btoa(escape(JSON.stringify(user)));
|
||||
this.storage.set(AuthConnstants.AUTH, encryptedValue);
|
||||
// Store the value
|
||||
async store(storageKey: string, value: any) {
|
||||
const encryptedValue = btoa(escape(JSON.stringify(value)));
|
||||
await Storage.set({
|
||||
key: storageKey,
|
||||
value: encryptedValue
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// 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;
|
||||
// Get the value
|
||||
async get(storageKey: string) {
|
||||
const ret = await Storage.get({ key: storageKey });
|
||||
return JSON.parse(unescape(atob(ret.value)));
|
||||
}
|
||||
|
||||
|
||||
/* async removeStorageItem(storageKey: string) {
|
||||
await this.storage.remove({ key: storageKey });
|
||||
} */
|
||||
async removeStorageItem(storageKey: string) {
|
||||
await Storage.remove({ key: storageKey });
|
||||
}
|
||||
|
||||
// Clear storage
|
||||
async clear() {
|
||||
await this.storage.clear();
|
||||
await Storage.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user