I am struggling with creating a feature in my Angular 14 an Ionic 6 app. I wish to make an “Welcome” screen in my app that appears only the first time that the user has opened an app and then never again.
I don’t know how to save that state that the users screen has already been seen by the user and the app should not load it upon second time opening the app…
My idea was to make a storage service that saves the state and then have a route guard that handles redirection and page showing...
I am now receiving this error and have no idea how to fix it... Am I ever corectly storing the value in the storage service or is my code totely wrong? ERROR:
Error: src/app/guards/first-load.guard.ts:17:50 - error TS2339: Property 'then' does not exist on type 'void'. [ng] [ng] 17
this.storageService.getValue('first_time').then((value) => { [ng]
My code is bellow:
storage.service.ts:
export class StorageService {
constructor(
private storage: Storage
) {
this.init();
}
async init() {
await this.storage.create();
}
setValue(key: 'first_time', value: 'done') {
this.storage.set(key, value);
}
getValue(key: 'first_time') {
this.storage.get(key).then((value) => {
console.log(value);
});
}
}
and here in the first-load.guard.ts I am calling this service:
export class FirstLoadGuard implements CanActivate {
constructor(
private storageService: StorageService,
private router: Router
) {}
canActivate(route: ActivatedRouteSnapshot): Promise<boolean>
{
return new Promise(resolve => {
this.storageService.getValue('first_time').then((value) => {
if (value !== null) {
this.router.navigateByUrl('/login');
resolve(false);
}
else {
this.storageService.setValue('first_time', 'done');
resolve(true);
}
});
});
}
}
If I need to provide more code feel free to just leave me a comment :) I wish someone could help me