I am facing an issue in my Quasar app with regards to browser refresh and firebase authentication.
After a user logs in and then clicks on the browser refresh, then the firebase.auth().currentUser returns null (as this executes asynchronously). This means that when the beforeEach gets executed the currentUser is null and the user is prompted with the logon page. However I see that when the callback to onAuthStateChanged is getting invoked the user is getting set correctly.
Is there any pattern by which, in a Quasar app, the onAuthStateChanged can be used in navigation process so that existing user session is reused?
// Vue-router => index.js
firebase.auth().onAuthStateChanged(user => {
console.log('onAuthStateChanged Invoked => ' + user);
});
router.beforeEach((to, from, next) => {
let currentUser = firebase.auth().currentUser;
let requiresAuth = to.matched.some(record => record.meta.requiresAuth);
if (requiresAuth && !currentUser) {
next('signin');
} else {
if (requiresAuth && currentUser.emailVerified === false) {
next('signin');
} else {
next();
}
}
});