Popup显示然后立即关闭

时间:2018-01-23 18:28:23

标签: firebase angularfire2

我尝试按照github上angularfire2文档的指南进行操作,但是当我尝试打开谷歌登录的弹出窗口时,它会立即关闭。

我尝试过不同的浏览器,但我无法弄清楚发生了什么。

这是我的表单组件的HTML:



<div class="container " >
<h2 class="date">Wallet manager</h2>
<h1>SUBBO</h1>

<form>
  <div class="form-group">
    <label class="date" for="exampleInputEmail1">Email address</label>
    <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
    <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
  </div>
  <div class="form-group">
    <label class="date" for="exampleInputPassword1">Password</label>
    <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
  </div>
  <button type="submit" (click)="login()" style="margin-top:20px" class="btn btn-outline-warning">Login</button>
  <button type="submit" (click)="logout()" style="margin-top:20px" class="btn btn-outline-warning">Logout</button>
</form>

</div>
&#13;
&#13;
&#13;

这是代码:

import { Component, OnInit } from '@angular/core';
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';

@Component({
  selector: 'app-login-form',
  templateUrl: './login-form.component.html',
  styleUrls: ['./login-form.component.css']
})
export class LoginFormComponent implements OnInit {

  constructor(public afAuth: AngularFireAuth) {
  }
  login() {
    this.afAuth.auth.signInWithPopup(new firebase.auth.GoogleProvider());
  }
  logout() {
    this.afAuth.auth.signOut();
  }

  ngOnInit() {
  }

}

使用登录按钮我调用Login(),我希望窗口弹出并保持在那里,但它会立即关闭。

我已将项目上传到Firebase,它给了我同样的问题: https://subbo-wallet-manager.firebaseapp.com/

3 个答案:

答案 0 :(得分:1)

使用Firebase身份验证时,我遇到了同样的问题。对我来说,解决方案是进入Firebase控制面板,选择我的项目,选择身份验证,然后在“登录方法”下将我的域添加到授权域列表中。一旦做到这一点,然后重新加载页面,它就可以工作。

答案 1 :(得分:0)

火基documentation给了我这个例子:

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;
  // ...
});

您的问题可能是缺少then()(可能会使其异步,不确定)。如果我的猜测是错误的,您仍然可以使用catch部分来查看是否发生了任何错误。也许提供者无效。

答案 2 :(得分:0)

我遇到了同样的问题,但就我而言,谷歌浏览器的登录失败,因此我尝试将谷歌浏览器的版本更新为最新版本,并且登录再次可以正常工作。