【问题标题】:firebase authentication with facebook - React Native使用 facebook 进行 firebase 身份验证 - React Native
【发布时间】:2018-10-16 16:05:03
【问题描述】:

我正在尝试通过 facebook 登录访问我的 react 本机应用程序。我在 android 上使用 fbsdk 和 firebase。这是我的功能:

loginConFacebookHandler = () => {
LoginManager.logInWithReadPermissions(['public_profile'])
.then(result => {
  if (result.isCancelled) {
    console.log('Cancelado')
    return Promise.reject(new Error('The user cancelled the request'));
  }
  console.log(`Login success with permissions: ${result.grantedPermissions.toString()}`);
  return AccessToken.getCurrentAccessToken();
})
.then(data => {
  const credential = firebase.auth.FacebookAuthProvider.credential(data.accessToken);      
  return firebase.auth().signInWithCredential(credential);
})
.then(currentUser => {
  console.log(`Facebook Login with user : ${JSON.stringify(currentUser.toJSON())}`);
  () => {startMainTabs()}
})
.catch(error => {
  console.log(`Login con facebook falló con error: ${error}`);
})

}

startMainTabs() 重定向到另一个屏幕。当我使用用户名和密码登录时,它可以完美运行:

loginUsuarioYContraseñaHandler = (email, password) => {
firebase.auth().signInWithEmailAndPassword(email, password)
.then(() => {startMainTabs()})
.catch(error => {alert(error)})
};

【问题讨论】:

    标签: firebase react-native fbsdk


    【解决方案1】:

    我认为问题在于您没有等待响应,您需要进行同步功能然后导航到另一个屏幕,这是我在另一个应用程序中使用的示例,希望您不能使用它。

    export async function facebookLogin() {
    let response;
    try {
        const result = await LoginManager.logInWithReadPermissions(['public_profile', 'email']);
        if (result.isCancelled) {
            response = "El usuario cancelo el inicio de sesion"
        } else {
            const data = await AccessToken.getCurrentAccessToken();
            if (!data) {
                response = "Hubo un error obteniendo los datos, cheque su internet";
            } else {
                const credential = firebase.auth.FacebookAuthProvider.credential(data.accessToken);
                await firebase.auth().signInAndRetrieveDataWithCredential(credential).then((user) => {
                    response = user;
                });
            }
        }
        return response;
    } catch (e) {
        response = (e.toString() === " An account already exists with the same email address but different sign-in credentials. Sign in using a provider associated with this email address.") ? "Usuario existente con el mismo coreo, intente con otro." : e.toString();
        return response;
    }
    

    }

    【讨论】:

    • 您的问题在于重定向或导航到您的其他屏幕?确保您为您的 Facebook 应用程序设置了配置,并执行此处列出的所有步骤。 (github.com/facebook/react-native-fbsdk)
    猜你喜欢
    • 2016-12-25
    • 2021-12-28
    • 1970-01-01
    • 2023-02-14
    • 2017-11-03
    • 2021-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多