我想为我的应用程序复制粘贴“使用Google的Firebase授权”流程 - 我确实有一个问题:它总是重定向到Google,即使它已经被授权并且立即退回。当用户最近经过身份验证并且是返回用户时,有没有办法让它不通过Google反弹?
Promise.resolve().then(function(){
return new Promise(function(resolve) {
console.group('init');
firebase.initializeApp({
apiKey: "MY KEY",
authDomain: "MINE.firebaseapp.com",
databaseURL: "https://MINE.firebaseio.com",
storageBucket: "MINE.appspot.com",
messagingSenderId: "ALSOMINE"
});
// Using this to make sure not in intermediate state
firebase.auth().onAuthStateChanged(function(user) {
console.log('User state stablilized.');
resolve();
});
});
}).then(function() {
// All the various login states
return new Promise(function(resolve, reject) {
if (firebase.auth().currentUser) {
console.log('You were already logged in - great!')
resolve(firebase.auth().currentUser);
}
firebase.auth().getRedirectResult().then(function(result) {
if (result.user) {
console.log('Welcome back and congratulations on your successful login!', result.user);
resolve(result.user);
} else {
console.log('Not logged in, not returning - time to send you on your way.');
var provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('https://www.googleapis.com/auth/plus.login');
firebase.auth().signInWithRedirect(provider);
console.log('You should never see this line because it redirected!');
}
}).catch(function(error) {
console.error('Returning from redirect login error:', error);
reject(error);
});
});
}).then(function(user) {
console.log('Signed in user', firebase.auth().currentUser.email);
// LETS ROCK
答案 0 :(得分:1)
致电后:
解析(firebase.auth()currentUser);
呼叫:
返回;