Я следовал приведенным ниже инструкциям для интеграции входа в Facebook в ReactJs https://firebase.google.com/docs/auth/web/facebook-login
Я также использую этот пакет реагирования: https://www.npmjs.com/package/react-facebook-login
Вот мой код
отобразить кнопку входа в Facebook:
<FacebookLogin
appId="1883333245015086"
autoLoad={false}
fields="name,email,picture"
callback={this.responseFacebook.bind(this)}
/>
Обработать результат Facebook:
responseFacebook(response) {
this.setState({loading: true});
if (response && response.authResponse) {
app.auth().signOut();
// User is signed-in Facebook.
var unsubscribe = firebase.auth().onAuthStateChanged(firebaseUser => {
unsubscribe();
// Check if we are already signed-in Firebase with the correct user.
if (!this._isFacebookUserEqual(response.authResponse, firebaseUser)) {
// Build Firebase credential with the Facebook auth token.
var credential = firebase.auth.FacebookAuthProvider.credential(
response.authResponse.accessToken);
// Sign in with the credential from the Facebook user.
firebase.auth().signInWithCredential(credential).catch(error => {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
// The email of the user's account used.
var email = error.email;
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
this.setState({error: errorMessage, loading: false});
}).then(() => {
app.auth().onAuthStateChanged((user) => {
if (user) {
user.getIdToken().then(idToken => {
// Session login endpoint is queried and the session cookie is set.
// CSRF protection should be taken into account.
const csrfToken = Utils.getCookie('csrfToken');
this.postIdTokenToSessionLogin('/auth/session-login', idToken, csrfToken, 'facebook');
});
} else {
this.setState({error: "There was an error", loading: false});
}
});
})
} else {
this.setState({error: "You are already a signed in", loading: false});
}
});
} else {
// User is signed-out of Facebook.
app.auth().signOut();
}
}
К сожалению, когда вызывается responseFacebook, не существует response.authResponse. Что я делаю не так?