getRedirectResult() not getting called (React)
The below method gets called when the "Signin with facebook" button is clicked. First, the app (Built with ReactJS) signs the user in by taking them to another page, then the app is supposed to take the user after the page redirects create a database entry IF the user didn't exist before (if signing in for the first time) or just redirect the user to another page IF the user existed. However, the code after signInWithRedirect() never gets called (probably due to the page reloading, which disrupts the flow of the application), how do I overcome this problem?
handleFacebookLogin = () => {
const provider = new firebase.auth.FacebookAuthProvider();
firebase.auth().signInWithRedirect(provider);
firebase.auth().getRedirectResult().then((result) => {
let user = result.user;
console.log(user);
db.collection('users').doc(user.uid).get()
.then((doc) => {
if(doc.exists) {
console.log('yes');
this.props.history.push(`/quiz/${user.uid}`);
} else {
db.collection('users').doc(user.uid).set({
name: user.displayName,
quiz: null
})
.then(() => {
this.props.history.push('/create-quiz');
}).catch((error) => {
alert(error.message);
});
}
}).catch((error) => {
alert(error.message);
})
}).catch((error) => {
alert(error.message);
})
}
Aucun commentaire:
Enregistrer un commentaire