Overview
I'm building a web app in Quasar/Vue.js and Firebase which needs to authenticate users.
What I'm trying to achieve
A pretty common feature - keep users logged even after they close the browser/tab.
Possible Solutions
I'm aware that I can use localStorage or cookies to set the user auth state. However, I want to allow Firebase auth do it for me (if it can do it).
I checked the docs in this regard - https://firebase.google.com/docs/auth/web/auth-state-persistence and they're nice, except I cannot figure out where to place this piece of code mentioned there:
firebase.auth().setPersistence(firebase.auth.Auth.Persistence.LOCAL)
.then(function() {
// New sign-in will be persisted with session persistence.
return firebase.auth().signInWithEmailAndPassword(email, password);
})
.catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
});
I'm not sure where to place it out of the following places:
- with the
onAuthStatechangedlistener? - in the App.vue (root Vue) instance?
- somewhere else?
Would be glad if anyone could help out. Thanks.