From 98217b537929359f7746b8d7dcfb2c60c4466141 Mon Sep 17 00:00:00 2001 From: gnbm Date: Wed, 4 Nov 2026 11:44:49 +0000 Subject: [PATCH] refactor(storage): replace @ionic/storage with @capacitor/preferences Swap the Ionic Storage wrapper for Capacitor Preferences in the user service, tutorial page, tutorial route guard and app component. Keys are unchanged; booleans are now stored as the string 'true'. Drop the IonicStorageModule bootstrap, the @ionic/storage packages and the localforage CommonJS allow-list entry, and register the native plugin via cap sync. Unit specs cover the login, tutorial and guard flows against the real Preferences web implementation. Closes FW-6671, relates to FW-6263. --- android/app/capacitor.build.gradle | 1 + android/capacitor.settings.gradle | 3 + angular.json | 1 - ios/App/CapApp-SPM/Package.swift | 2 + package-lock.json | 69 +++---------------- package.json | 3 +- src/app/app.component.spec.ts | 14 ++-- src/app/app.component.ts | 7 +- src/app/pages/tutorial/tutorial.spec.ts | 42 ++++++++--- src/app/pages/tutorial/tutorial.ts | 9 ++- .../providers/check-tutorial.guard.spec.ts | 38 ++++++++++ src/app/providers/check-tutorial.guard.ts | 8 +-- src/app/providers/user.service.spec.ts | 38 ++++++++++ src/app/providers/user.service.ts | 25 +++---- src/main.ts | 2 - 15 files changed, 157 insertions(+), 105 deletions(-) create mode 100644 src/app/providers/check-tutorial.guard.spec.ts create mode 100644 src/app/providers/user.service.spec.ts diff --git a/android/app/capacitor.build.gradle b/android/app/capacitor.build.gradle index 87b99847b..5854cdf50 100644 --- a/android/app/capacitor.build.gradle +++ b/android/app/capacitor.build.gradle @@ -13,6 +13,7 @@ dependencies { implementation project(':capacitor-device') implementation project(':capacitor-haptics') implementation project(':capacitor-keyboard') + implementation project(':capacitor-preferences') implementation project(':capacitor-splash-screen') implementation project(':capacitor-status-bar') diff --git a/android/capacitor.settings.gradle b/android/capacitor.settings.gradle index 02c391fef..89a0a94ed 100644 --- a/android/capacitor.settings.gradle +++ b/android/capacitor.settings.gradle @@ -14,6 +14,9 @@ project(':capacitor-haptics').projectDir = new File('../node_modules/@capacitor/ include ':capacitor-keyboard' project(':capacitor-keyboard').projectDir = new File('../node_modules/@capacitor/keyboard/android') +include ':capacitor-preferences' +project(':capacitor-preferences').projectDir = new File('../node_modules/@capacitor/preferences/android') + include ':capacitor-splash-screen' project(':capacitor-splash-screen').projectDir = new File('../node_modules/@capacitor/splash-screen/android') diff --git a/angular.json b/angular.json index dc8760de7..7ca3fe178 100644 --- a/angular.json +++ b/angular.json @@ -55,7 +55,6 @@ "defaultConfiguration": "", "options": { "allowedCommonJsDependencies": [ - "localforage", "leaflet" ], "assets": [ diff --git a/ios/App/CapApp-SPM/Package.swift b/ios/App/CapApp-SPM/Package.swift index 1770034bd..f85a1001b 100644 --- a/ios/App/CapApp-SPM/Package.swift +++ b/ios/App/CapApp-SPM/Package.swift @@ -16,6 +16,7 @@ let package = Package( .package(name: "CapacitorDevice", path: "../../../node_modules/@capacitor/device"), .package(name: "CapacitorHaptics", path: "../../../node_modules/@capacitor/haptics"), .package(name: "CapacitorKeyboard", path: "../../../node_modules/@capacitor/keyboard"), + .package(name: "CapacitorPreferences", path: "../../../node_modules/@capacitor/preferences"), .package(name: "CapacitorSplashScreen", path: "../../../node_modules/@capacitor/splash-screen"), .package(name: "CapacitorStatusBar", path: "../../../node_modules/@capacitor/status-bar") ], @@ -29,6 +30,7 @@ let package = Package( .product(name: "CapacitorDevice", package: "CapacitorDevice"), .product(name: "CapacitorHaptics", package: "CapacitorHaptics"), .product(name: "CapacitorKeyboard", package: "CapacitorKeyboard"), + .product(name: "CapacitorPreferences", package: "CapacitorPreferences"), .product(name: "CapacitorSplashScreen", package: "CapacitorSplashScreen"), .product(name: "CapacitorStatusBar", package: "CapacitorStatusBar") ] diff --git a/package-lock.json b/package-lock.json index 43c986870..c35adab65 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,10 +24,10 @@ "@capacitor/haptics": "^8.0.0", "@capacitor/ios": "^8.0.0", "@capacitor/keyboard": "^8.0.0", + "@capacitor/preferences": "^8.0.1", "@capacitor/splash-screen": "^8.0.0", "@capacitor/status-bar": "^8.0.0", "@ionic/angular": "^9.0.0", - "@ionic/storage-angular": "^4.0.0", "core-js": "^3.6.4", "leaflet": "^1.9.4", "rxjs": "^7.8.0", @@ -51,7 +51,6 @@ "@eslint/js": "^9.20.0", "@ionic/angular-toolkit": "^13.0.0", "@ionic/cli": "7.2.1", - "@ionic/storage": "^3.0.6", "@types/jasmine": "~5.1.0", "@types/leaflet": "^1.9.17", "@types/node": "^12.11.1", @@ -4034,6 +4033,15 @@ "@capacitor/core": ">=8.0.0" } }, + "node_modules/@capacitor/preferences": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/@capacitor/preferences/-/preferences-8.0.1.tgz", + "integrity": "sha512-T6no3ebi79XJCk91U3Jp/liJUwgBdvHR+s6vhvPkPxSuch7z3zx5Rv1bdWM6sWruNx+pViuEGqZvbfCdyBvcHQ==", + "license": "MIT", + "peerDependencies": { + "@capacitor/core": ">=8.0.0" + } + }, "node_modules/@capacitor/splash-screen": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/@capacitor/splash-screen/-/splash-screen-8.0.2.tgz", @@ -5141,39 +5149,6 @@ "node": ">= 16" } }, - "node_modules/@ionic/storage": { - "version": "3.0.6", - "resolved": "https://registry.npmjs.org/@ionic/storage/-/storage-3.0.6.tgz", - "integrity": "sha512-sw+zSJINIpbQCGZR9mEtb9N0WmZLuhcMVqOZJBqLuDACAMdXqG39zmp5nSVqhGI1/9X3nd0K5gVn6icyVfUnUg==", - "dev": true, - "license": "MIT", - "dependencies": { - "localforage": "^1.9.0" - } - }, - "node_modules/@ionic/storage-angular": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/@ionic/storage-angular/-/storage-angular-4.0.0.tgz", - "integrity": "sha512-FeSmCMCm1bMRfu5TFSqLtjdfEo/dLLUhLIrPmbhSYomVZdV/dNn4mBZv9SabyxSqn4bF31hw40y+4buhG+durQ==", - "license": "MIT", - "dependencies": { - "@ionic/storage": "^4.0.0", - "tslib": "^2.3.0" - }, - "peerDependencies": { - "@angular/core": "*", - "rxjs": "*" - } - }, - "node_modules/@ionic/storage-angular/node_modules/@ionic/storage": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/@ionic/storage/-/storage-4.0.0.tgz", - "integrity": "sha512-3N21P19Xk6cICLnSXZ3ilRqbSXAGSFeIF3HNqz+1kARcm0UFT/vwmZreaXtFyq437vvEWOfJ2enlj3JHLKS0FA==", - "license": "MIT", - "dependencies": { - "localforage": "^1.9.0" - } - }, "node_modules/@ionic/utils-array": { "version": "2.1.6", "resolved": "https://registry.npmjs.org/@ionic/utils-array/-/utils-array-2.1.6.tgz", @@ -13170,12 +13145,6 @@ "node": ">=0.10.0" } }, - "node_modules/immediate": { - "version": "3.0.6", - "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz", - "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==", - "license": "MIT" - }, "node_modules/immutable": { "version": "5.1.7", "resolved": "https://registry.npmjs.org/immutable/-/immutable-5.1.7.tgz", @@ -14662,15 +14631,6 @@ } } }, - "node_modules/lie": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/lie/-/lie-3.1.1.tgz", - "integrity": "sha512-RiNhHysUjhrDQntfYSfY4MU24coXXdEOgw9WGcKHNeEwffDYbF//u87M1EWaMGzuFoSbqW0C9C6lEEhDOAswfw==", - "license": "MIT", - "dependencies": { - "immediate": "~3.0.5" - } - }, "node_modules/lightningcss": { "version": "1.33.0", "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.33.0.tgz", @@ -15100,15 +15060,6 @@ "node": ">= 12.13.0" } }, - "node_modules/localforage": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/localforage/-/localforage-1.10.0.tgz", - "integrity": "sha512-14/H1aX7hzBBmmh7sGPd+AOMkkIrHM3Z1PAyGgZigA1H1p5O5ANnMyWzvpAETtG68/dC4pC0ncy3+PPGzXZHPg==", - "license": "Apache-2.0", - "dependencies": { - "lie": "3.1.1" - } - }, "node_modules/locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", diff --git a/package.json b/package.json index 7a1257408..ec4d0c61b 100644 --- a/package.json +++ b/package.json @@ -36,10 +36,10 @@ "@capacitor/haptics": "^8.0.0", "@capacitor/ios": "^8.0.0", "@capacitor/keyboard": "^8.0.0", + "@capacitor/preferences": "^8.0.1", "@capacitor/splash-screen": "^8.0.0", "@capacitor/status-bar": "^8.0.0", "@ionic/angular": "^9.0.0", - "@ionic/storage-angular": "^4.0.0", "core-js": "^3.6.4", "leaflet": "^1.9.4", "rxjs": "^7.8.0", @@ -63,7 +63,6 @@ "@eslint/js": "^9.20.0", "@ionic/angular-toolkit": "^13.0.0", "@ionic/cli": "7.2.1", - "@ionic/storage": "^3.0.6", "@types/jasmine": "~5.1.0", "@types/leaflet": "^1.9.17", "@types/node": "^12.11.1", diff --git a/src/app/app.component.spec.ts b/src/app/app.component.spec.ts index 05e0aa2aa..092c7754d 100644 --- a/src/app/app.component.spec.ts +++ b/src/app/app.component.spec.ts @@ -2,14 +2,13 @@ import { provideHttpClient } from '@angular/common/http'; import { provideHttpClientTesting } from '@angular/common/http/testing'; import { CUSTOM_ELEMENTS_SCHEMA, - importProvidersFrom, provideZonelessChangeDetection, } from '@angular/core'; import { TestBed } from '@angular/core/testing'; import { provideRouter } from '@angular/router'; import { SwUpdate } from '@angular/service-worker'; +import { Preferences } from '@capacitor/preferences'; import { MenuController, provideIonicAngular } from '@ionic/angular'; -import { IonicStorageModule } from '@ionic/storage-angular'; import { AppComponent } from './app.component'; import { routes } from './app.routes'; import { UserService } from './providers/user.service'; @@ -18,6 +17,7 @@ describe('AppComponent', () => { let menuSpy, userDataSpy, swUpdateSpy, app: AppComponent, fixture; beforeEach(async () => { + await Preferences.clear(); menuSpy = jasmine.createSpyObj('MenuController', ['toggle', 'enable']); userDataSpy = jasmine.createSpyObj('UserService', ['isLoggedIn', 'logout']); userDataSpy.isLoggedIn.and.returnValue(Promise.resolve(false)); @@ -38,7 +38,6 @@ describe('AppComponent', () => { provideRouter(routes), provideHttpClient(), provideHttpClientTesting(), - importProvidersFrom(IonicStorageModule.forRoot()), { provide: MenuController, useValue: menuSpy }, { provide: UserService, useValue: userDataSpy }, { provide: SwUpdate, useValue: swUpdateSpy }, @@ -48,11 +47,18 @@ describe('AppComponent', () => { beforeEach(() => { fixture = TestBed.createComponent(AppComponent); app = fixture.debugElement.componentInstance; - app['storage'].create(); fixture.detectChanges(); }); it('should create the app', () => { expect(app).toBeTruthy(); }); + + it('should reset the tutorial flag when opening the tutorial', async () => { + await Preferences.set({ key: 'ion_did_tutorial', value: 'true' }); + + app.openTutorial(); + + expect((await Preferences.get({ key: 'ion_did_tutorial' })).value).toBe('false'); + }); }); diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 23b3f913a..73d04417e 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -3,11 +3,10 @@ import { Router, RouterLink, RouterLinkActive } from '@angular/router'; import { SwUpdate } from '@angular/service-worker'; import { addIcons } from 'ionicons'; +import { Preferences } from '@capacitor/preferences'; import { SplashScreen } from '@capacitor/splash-screen'; import { StatusBar } from '@capacitor/status-bar'; -import { Storage } from '@ionic/storage-angular'; - import { FormsModule } from '@angular/forms'; import { IonApp, @@ -67,7 +66,6 @@ import { UserService } from './providers/user.service'; }) export class AppComponent implements OnInit { private router = inject(Router); - private storage = inject(Storage); private userService = inject(UserService); private swUpdate = inject(SwUpdate); private toastCtrl = inject(ToastController); @@ -117,7 +115,6 @@ export class AppComponent implements OnInit { async ngOnInit() { this.initializeApp(); - await this.storage.create(); this.checkLoginStatus(); this.listenForLoginEvents(); @@ -185,7 +182,7 @@ export class AppComponent implements OnInit { openTutorial() { this.menu.enable(false); - this.storage.set('ion_did_tutorial', false); + Preferences.set({ key: 'ion_did_tutorial', value: 'false' }); this.router.navigateByUrl('/tutorial'); } diff --git a/src/app/pages/tutorial/tutorial.spec.ts b/src/app/pages/tutorial/tutorial.spec.ts index 534528e42..75c1d3c54 100644 --- a/src/app/pages/tutorial/tutorial.spec.ts +++ b/src/app/pages/tutorial/tutorial.spec.ts @@ -1,23 +1,24 @@ import { CUSTOM_ELEMENTS_SCHEMA, - importProvidersFrom, provideZonelessChangeDetection, } from '@angular/core'; import { TestBed } from '@angular/core/testing'; import { Router, provideRouter } from '@angular/router'; +import { Preferences } from '@capacitor/preferences'; import { MenuController, provideIonicAngular } from '@ionic/angular'; -import { IonicStorageModule } from '@ionic/storage-angular'; import { routes } from '../../app.routes'; import { TutorialPage } from './tutorial'; describe('TutorialPage', () => { - let fixture, app: TutorialPage; + let fixture, app: TutorialPage, routerSpy: jasmine.SpyObj; beforeEach(async () => { + await Preferences.clear(); const menuSpy = jasmine.createSpyObj('MenuController', [ 'toggle', 'enable', ]); - const routerSpy = jasmine.createSpyObj('Router', ['navigateByUrl']); + routerSpy = jasmine.createSpyObj('Router', ['navigateByUrl']); + routerSpy.navigateByUrl.and.returnValue(Promise.resolve(true)); await TestBed.configureTestingModule({ declarations: [], @@ -27,7 +28,6 @@ describe('TutorialPage', () => { provideZonelessChangeDetection(), provideIonicAngular({ useSetInputAPI: true }), provideRouter(routes), - importProvidersFrom(IonicStorageModule.forRoot()), { provide: MenuController, useValue: menuSpy }, { provide: Router, useValue: routerSpy }, ], @@ -37,14 +37,38 @@ describe('TutorialPage', () => { beforeEach(() => { fixture = TestBed.createComponent(TutorialPage); app = fixture.debugElement.componentInstance; - app.storage.create(); }); it('should create the tutorial page', () => { expect(app).toBeTruthy(); }); - it('should check the tutorial status', async () => { - const didTuts = await app.storage.get('ion_did_tutorial'); - expect(didTuts).toBeFalsy(); + it('should stay on the tutorial when it was not completed yet', async () => { + app.ionViewWillEnter(); + await Preferences.get({ key: 'ion_did_tutorial' }); + + expect(routerSpy.navigateByUrl).not.toHaveBeenCalled(); + }); + + it('should persist the tutorial as done when starting the app', async () => { + app.startApp(); + await routerSpy.navigateByUrl.calls.mostRecent().returnValue; + + expect(routerSpy.navigateByUrl).toHaveBeenCalledWith( + '/app/tabs/schedule', + { replaceUrl: true } + ); + expect((await Preferences.get({ key: 'ion_did_tutorial' })).value).toBe('true'); + }); + + it('should skip to the schedule when the tutorial was already done', async () => { + await Preferences.set({ key: 'ion_did_tutorial', value: 'true' }); + + app.ionViewWillEnter(); + await Preferences.get({ key: 'ion_did_tutorial' }); + + expect(routerSpy.navigateByUrl).toHaveBeenCalledWith( + '/app/tabs/schedule', + { replaceUrl: true } + ); }); }); diff --git a/src/app/pages/tutorial/tutorial.ts b/src/app/pages/tutorial/tutorial.ts index 7a59e5679..e80297584 100644 --- a/src/app/pages/tutorial/tutorial.ts +++ b/src/app/pages/tutorial/tutorial.ts @@ -10,7 +10,7 @@ import { IonToolbar, MenuController, } from '@ionic/angular'; -import { Storage } from '@ionic/storage-angular'; +import { Preferences } from '@capacitor/preferences'; import { addIcons } from 'ionicons'; import { arrowForward, close } from 'ionicons/icons'; @@ -23,7 +23,6 @@ import { arrowForward, close } from 'ionicons/icons'; export class TutorialPage { menu = inject(MenuController); router = inject(Router); - storage = inject(Storage); showSkip = true; @@ -37,12 +36,12 @@ export class TutorialPage { startApp() { this.router .navigateByUrl('/app/tabs/schedule', { replaceUrl: true }) - .then(() => this.storage.set('ion_did_tutorial', true)); + .then(() => Preferences.set({ key: 'ion_did_tutorial', value: 'true' })); } ionViewWillEnter() { - this.storage.get('ion_did_tutorial').then(res => { - if (res === true) { + Preferences.get({ key: 'ion_did_tutorial' }).then(({ value }) => { + if (value === 'true') { this.router.navigateByUrl('/app/tabs/schedule', { replaceUrl: true }); } }); diff --git a/src/app/providers/check-tutorial.guard.spec.ts b/src/app/providers/check-tutorial.guard.spec.ts new file mode 100644 index 000000000..48d0e2523 --- /dev/null +++ b/src/app/providers/check-tutorial.guard.spec.ts @@ -0,0 +1,38 @@ +import { provideZonelessChangeDetection } from '@angular/core'; +import { TestBed } from '@angular/core/testing'; +import { Router } from '@angular/router'; +import { Preferences } from '@capacitor/preferences'; +import { Observable, firstValueFrom } from 'rxjs'; +import { checkTutorialGuard } from './check-tutorial.guard'; + +describe('checkTutorialGuard', () => { + let routerSpy: jasmine.SpyObj; + + beforeEach(async () => { + await Preferences.clear(); + routerSpy = jasmine.createSpyObj('Router', ['navigate']); + TestBed.configureTestingModule({ + providers: [ + provideZonelessChangeDetection(), + { provide: Router, useValue: routerSpy }, + ], + }); + }); + + const runGuard = () => + firstValueFrom( + TestBed.runInInjectionContext(() => checkTutorialGuard()) as Observable + ); + + it('should allow the tutorial route when the tutorial was not done', async () => { + expect(await runGuard()).toBe(true); + expect(routerSpy.navigate).not.toHaveBeenCalled(); + }); + + it('should redirect to the schedule when the tutorial was already done', async () => { + await Preferences.set({ key: 'ion_did_tutorial', value: 'true' }); + + expect(await runGuard()).toBe(false); + expect(routerSpy.navigate).toHaveBeenCalledWith(['/app', 'tabs', 'schedule']); + }); +}); diff --git a/src/app/providers/check-tutorial.guard.ts b/src/app/providers/check-tutorial.guard.ts index 325a93100..fbac22fbb 100644 --- a/src/app/providers/check-tutorial.guard.ts +++ b/src/app/providers/check-tutorial.guard.ts @@ -1,15 +1,15 @@ import { inject } from '@angular/core'; import { Router } from '@angular/router'; -import { Storage } from '@ionic/storage-angular'; +import { Preferences } from '@capacitor/preferences'; import { from, map, tap } from 'rxjs'; export const checkTutorialGuard = () => { - const storage = inject(Storage); const router = inject(Router); - return from(storage.get('ion_did_tutorial')).pipe( + return from(Preferences.get({ key: 'ion_did_tutorial' })).pipe( + map(({ value }) => value === 'true'), tap(didTutorial => { - if (didTutorial === true) { + if (didTutorial) { router.navigate(['/app', 'tabs', 'schedule']); } }), diff --git a/src/app/providers/user.service.spec.ts b/src/app/providers/user.service.spec.ts new file mode 100644 index 000000000..4205d7468 --- /dev/null +++ b/src/app/providers/user.service.spec.ts @@ -0,0 +1,38 @@ +import { provideZonelessChangeDetection } from '@angular/core'; +import { TestBed } from '@angular/core/testing'; +import { Preferences } from '@capacitor/preferences'; +import { UserService } from './user.service'; + +describe('UserService', () => { + let service: UserService; + + beforeEach(async () => { + await Preferences.clear(); + TestBed.configureTestingModule({ + providers: [provideZonelessChangeDetection()], + }); + service = TestBed.inject(UserService); + }); + + it('should not be logged in when nothing is stored', async () => { + expect(await service.isLoggedIn()).toBe(false); + expect(await service.getUsername()).toBeNull(); + }); + + it('should persist the login state and username in Preferences', async () => { + await service.login('Bob'); + + expect(await service.isLoggedIn()).toBe(true); + expect(await service.getUsername()).toBe('Bob'); + expect((await Preferences.get({ key: 'hasLoggedIn' })).value).toBe('true'); + expect((await Preferences.get({ key: 'username' })).value).toBe('Bob'); + }); + + it('should clear the login state and username on logout', async () => { + await service.signup('Alice'); + await service.logout(); + + expect(await service.isLoggedIn()).toBe(false); + expect(await service.getUsername()).toBeNull(); + }); +}); diff --git a/src/app/providers/user.service.ts b/src/app/providers/user.service.ts index d8096c41c..437196d4c 100644 --- a/src/app/providers/user.service.ts +++ b/src/app/providers/user.service.ts @@ -1,12 +1,10 @@ -import { Injectable, inject } from '@angular/core'; -import { Storage } from '@ionic/storage-angular'; +import { Injectable } from '@angular/core'; +import { Preferences } from '@capacitor/preferences'; @Injectable({ providedIn: 'root', }) export class UserService { - storage = inject(Storage); - favorites: string[] = []; HAS_LOGGED_IN = 'hasLoggedIn'; HAS_SEEN_TUTORIAL = 'hasSeenTutorial'; @@ -27,24 +25,23 @@ export class UserService { } login(username: string): Promise { - return this.storage.set(this.HAS_LOGGED_IN, true).then(() => { + return Preferences.set({ key: this.HAS_LOGGED_IN, value: 'true' }).then(() => { this.setUsername(username); return window.dispatchEvent(new CustomEvent('user:login')); }); } signup(username: string): Promise { - return this.storage.set(this.HAS_LOGGED_IN, true).then(() => { + return Preferences.set({ key: this.HAS_LOGGED_IN, value: 'true' }).then(() => { this.setUsername(username); return window.dispatchEvent(new CustomEvent('user:signup')); }); } logout(): Promise { - return this.storage - .remove(this.HAS_LOGGED_IN) + return Preferences.remove({ key: this.HAS_LOGGED_IN }) .then(() => { - return this.storage.remove('username'); + return Preferences.remove({ key: 'username' }); }) .then(() => { window.dispatchEvent(new CustomEvent('user:logout')); @@ -52,18 +49,18 @@ export class UserService { } setUsername(username: string): Promise { - return this.storage.set('username', username); + return Preferences.set({ key: 'username', value: username }); } - getUsername(): Promise { - return this.storage.get('username').then(value => { + getUsername(): Promise { + return Preferences.get({ key: 'username' }).then(({ value }) => { return value; }); } isLoggedIn(): Promise { - return this.storage.get(this.HAS_LOGGED_IN).then(value => { - return value === true; + return Preferences.get({ key: this.HAS_LOGGED_IN }).then(({ value }) => { + return value === 'true'; }); } } diff --git a/src/main.ts b/src/main.ts index c7966c141..286e0415f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -19,7 +19,6 @@ import { provideServiceWorker, ServiceWorkerModule, } from '@angular/service-worker'; -import { IonicStorageModule } from '@ionic/storage-angular'; import { AppComponent } from './app/app.component'; import { routes } from './app/app.routes'; import { environment } from './environments/environment'; @@ -41,7 +40,6 @@ bootstrapApplication(AppComponent, { ), provideHttpClient(), importProvidersFrom( - IonicStorageModule.forRoot(), ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production, })