I am currently working on an app using Ionic, Angular2, and Firebase.
My approach involves saving the auth.currentUser
information in the localStorage
when a user logs in or registers. However, I recently discovered that having the user
variable set in the localStorage
doesn't necessarily mean the user is signed in.
This is how my localStorage
variable user
looks:
https://i.sstatic.net/REdpv.png
And this is how I retrieve it:
ngOnInit() {
Promise.all([ //data storage get all..
this.storage.get('user')
])
.then(([user]) => {
this.userData = user; //set the user storage to this.userData
console.log(this.userData)
})
.catch(error => {
console.log("Storage Error.");
});
}
I have all the user's information stored, but they are not actually signed in. When I check using:
this.afAuth.auth.onAuthStateChanged((user) => {
if (user) {
console.log(user)
} else {
console.log("Not logged in")
}
});
It shows that the user isn't logged in. Is there a way for me to maintain the user's login status while utilizing the localStorage information?
Alternatively, can I ensure that the login state remains logged in unless the user explicitly signs out? Without any expiration?
What steps should I take from here? Any suggestions would be greatly appreciated! Thank you.