请注意,由于需要解释,问题可能会很长,否则它可能会非常模糊并导致相同的旧答案。
我在创建时遇到问题Google Sign-In
页面进入React Native
using firebase。基于firebase文档:
随着 3.1.0 SDK 的更新,几乎所有的 JavaScript SDK
功能现在应该可以在 React Native 中顺利运行。但是这里有
一些注意事项:
- “Headful” auth 方法(例如 signInWithPopup()、signInWithRedirect()、linkWithPopup() 和 linkWithRedirect())不会
使用 React Native(或 Cordova)工作。您仍然可以签名
通过使用在联合提供商中或与联合提供商链接
signInWithCredential()
使用您选择的提供商提供的 OAuth 令牌。
这意味着我cannot在我的中使用以下代码反应本机项目:
var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithPopup(provider).then(function(result) {
// This gives you a Google Access Token. You can use it to access the Google API.
var token = result.credential.accessToken;
// The signed-in user info.
var user = result.user;
// ...
}).catch(function(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;
// ...
});
然后通过谷歌搜索并搜索了数十个 stackoverflow,我发现了以下使用方法谷歌登录 using Firebase API
in 反应本机项目为:
const provider = firebase.auth.GoogleAuthProvider;
const credential = provider.credential(token);
firebase.auth().signInWithCredential(credential)
.then((data) => {
console.log('SUCCESS', data);
})
.catch((error) => {
console.log('ERROR', error)
});
Now in 就在上面的代码,你可能已经注意到token在以下行中:
const 凭证 = 提供商.凭证(token);
所以基于firebase文档,token得到如下:
// `googleUser` from the onsuccess Google Sign In callback.
var token = googleUser.getAuthResponse().id_token;
所以我的问题是我如何获得它token使用 GoogleUser 对象或它所在的任何对象反应本机?或者还有别的办法吗?