I'm trying to use ngOnInit to verify if a value is set on the app's localStorage, but it doesn't work.
this is what i have now:
this is the function that logs the user in the app
async login() {
try {
await this.authService.SignUpWithEmail(this.email, this.password);
await this.router.navigate(['secundaria']);
localStorage.setItem("logged-status", "logged-in")
}
this is what verify if the value is in the local storage
ngOnInit() {
if (localStorage.getItem("logged-in" ) !== null) {
this.navCtrl.navigateForward(["quarta"])
}
}
It seems like the app isn't running the code, since it doesn't work at all.
Can someone help me? I'm trying to do this for an hour now and it doesn't work
The navigate might be destroying the component before the bottom commmand gets executed. Always place the navigate command at the last to ensure all the code gets executed.
async login() {
try {
await this.authService.SignUpWithEmail(this.email, this.password);
localStorage.setItem("logged-status", "logged-in");
this.router.navigate(['secundaria']); // <- changed here!
}