I have a Vue app where is implemented firebase as BaaS.
To check when the user is authenticated I'm using the onAuthStateChanged method that is provided out of the box from firebase, but it's giving me a problem.
In detail, I'm checking if an user never logged in to the app using an auth provider and registered into the RTDB database by compiling the form, by checking the authResult.additionalUserInfo.isNewUser that is provided from the callback of firebase UI, but this have a downside that I need to fix.
In fact I'm not able to show the registration form after success callback is called also if the isNewUser condition is true because when onAuthStateChanged is called and the user isn't null it will ignore my if() stetement. I'm using this method to show the firebase ui and manage this condition:
showFirebaseLoginUI() {
fbui.start(this.$refs.firebaseWidget, {
signInOptions: [
firebase.auth.EmailAuthProvider.PROVIDER_ID,
firebase.auth.GoogleAuthProvider.PROVIDER_ID,
firebase.auth.TwitterAuthProvider.PROVIDER_ID,
firebase.auth.FacebookAuthProvider.PROVIDER_ID,
],
callbacks: {
signInSuccessWithAuthResult: (authResult) => {
console.log(authResult)
if( authResult.additionalUserInfo.isNewUser ){
console.log('New user')
this.showWizard = true
} else {
this.$router.push({ name: 'Home' })
}
}
},
signInFlow: 'popup'
});
}
The console log will be displayed, but wizard will not and the user will be redirected directly to the homepage
created() {
onAuthStateChanged(getAuth(app), (user) => {
if( user && !this.showWizard ){
this.$router.push({ name: 'Home' })
}
})
}
Since I need to add the user to the database after he add some information and when an user is already logged avoid that the login page will be displayed, how I can fix this?