2017-11-18 4 views
0

これまでは動作していました。AngularFireAuthによるAngular4 Googleの認証は、ユーザーがGoogleにログインする前にソースページにリダイレクトされます。

しかし、ブラウザは長いURLにリダイレクトされ、すぐにソースURLに戻ります。あなたのGoogleアカウントにログインする機会はありません。

import { AngularFireAuth } from 'angularfire2/auth'; 
 
    import { Injectable } from '@angular/core'; 
 
    import * as firebase from 'firebase'; 
 
    import {Observable} from 'rxjs/Observable'; 
 
    import { Router, ActivatedRoute } from '@angular/router'; 
 
    import { AngularFirestore, AngularFirestoreCollection } from 'angularfire2/firestore'; 
 
    import 'rxjs/add/operator/map'; 
 
    import {AppUser} from './model'; 
 
    import {RepositoryService} from './repository.service'; 
 
    import 'rxjs/add/observable/of'; 
 

 

 
    @Injectable() 
 
    export class AuthService { 
 
    public user$: Observable<firebase.User>; 
 
    constructor(private readonly afs: AngularFirestore, private afAuth: AngularFireAuth, 
 
     private repo: RepositoryService, private router: Router, private route: ActivatedRoute) { 
 
     this.user$ = afAuth.authState; 
 
    } 
 

 
    login() { 
 
      const returnUrl = this.route.snapshot.queryParamMap.get('returnUrl') || '/'; 
 
      localStorage.setItem('returnUrl', returnUrl); 
 
      alert('should be authenticating with google now'); 
 
      const provider = new firebase.auth.GoogleAuthProvider; 
 
      this.afAuth.auth.signInWithRedirect(provider); 
 
    }

providers: [AngularFireAuth, AuthService, AuthGuardService, RepositoryService, AdminGuardService], 
 
    bootstrap: [AppComponent]
は私のデータベースの

Googleの認証を有効になっている認証サービス enter image description here

enter image description here

+0

ブラウザコンソールに間違いやネットワーク要求を検査し、それらを報告することはできますか? – bojeil

+0

私はこれらのキーが見えることを気にしない完全なライフサイクルのためにネットワークタブのhttpログを追加しました。それは単なるテストデータベースです。 – arod

+0

追加するのを忘れてしまったようです。あなたのログは表示されません。 – bojeil

答えて

0

私はfirebase.authは()。signInWithRedirectは、デフォルトで、またはGoogleアカウントからログアウトして、代わりにちょうどあなたが別のアカウントを持っているかもしれないという事実を無視することができるようになることを想定していましたあなたは認証に使いたいと思う。ただし、これを行うには次のような、カスタムパラメータを設定する必要があります:あなたは

 const provider = new firebase.auth.GoogleAuthProvider(); 

    provider.setCustomParameters({ 
      prompt: 'select_account' 
    }); 
    firebase.auth().signInWithRedirect(provider); 
関連する問題