I'm wondering if it's an okay practice to set a uid variable onAuthStateChanged() and use this uid throughout my app to determine if a user is logged in or not. This way I don't have to use firebase.auth().currentUser.uid or have multiple onAuthStateChanged() methods throughout my code.
firebase.auth().onAuthStateChanged(user => {
if (user)
this.uid = user.uid;
else
this.uid = null
})
Even if a hacker changed this uid variable it still wouldn't give him access to a users database because of my rules, so is this an okay practice?
Now in my code I will check this.uid to see if a user is logged in and also use this.uid to retrieve user data.
I ask because I'm starting to use auth().currentUser a lot to check if a user is logged in and it would be much faster to just save the login status locally to this.uid when onAuthStateChanged, if it doesn't pose any security risks. This just seems like common sense to me but I'm still new to Firebase and haven't seen this practice in the examples so I have to question it.