firebaseAuth GoogleAuthProvider()signInWithRedirect [英] firebaseAuth GoogleAuthProvider() signInWithRedirect
问题描述
我在我的应用中使用了重定向的Google身份验证,并且我想在身份验证完成后重定向。
但承诺不起作用
$ b $ pre $函数loginGoogle(){
var provider = new firebase.auth .GoogleAuthProvider();
firebase.auth()。signInWithRedirect(provider);
firebase.auth()。getRedirectResult()。then(function(result){
//这会给你一个Google Access令牌,你可以用它来访问Google API
if (result.credential){
var token = result.credential.accessToken;
console.log('token'+ token);
}
//登录用户info
var user = result.user;
console.log('user'+ user);
//如果成功重定向到
$ state.go('maps- ();
// ...
})。catch(function(error){
// Handle Errors here。
var errorCode = error。代码;
console.log(errorCode);
var errorMessage = error.message;
//使用的用户帐号的电子邮件
console.log(errorMessage);
var email = error.email;
consol e.log(email);
//使用的firebase.auth.AuthCredential类型。
var credential = error.credential;
console.log(凭证);
// ...
});
$ / code>
谢谢。
getRedirectResult()
调用移出您的 loginGoogle()
函数。应该在页面加载时调用 getRedirectResult()
。一个例子可以在这里找到: https://github.com/firebase/quickstart-js/blob/master/auth/google-redirect.html
I've a authentication Google with redirect in my app, and I would like just redirect when authentication is completely finished. But the promise is not working
function loginGoogle() {
var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithRedirect(provider);
firebase.auth().getRedirectResult().then(function (result) {
// This gives you a Google Access Token. You can use it to access the Google API.
if (result.credential) {
var token = result.credential.accessToken;
console.log('token ' + token);
}
// The signed-in user info.
var user = result.user;
console.log('user ' + user);
// if success redirect to
$state.go('maps-fullwidth');
// ...
}).catch(function (error) {
// Handle Errors here.
var errorCode = error.code;
console.log(errorCode);
var errorMessage = error.message;
// The email of the user's account used.
console.log(errorMessage);
var email = error.email;
console.log(email);
// The firebase.auth.AuthCredential type that was used.
var credential = error.credential;
console.log(credential);
// ...
});
}
Thanks.
Move the getRedirectResult()
call out of your loginGoogle()
function. getRedirectResult()
should be called on page load. An example of this in action can be found here:
https://github.com/firebase/quickstart-js/blob/master/auth/google-redirect.html
这篇关于firebaseAuth GoogleAuthProvider()signInWithRedirect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!