Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ionic重定向问题中的angular firebase auth Signin WithRedirect_Angular_Ionic Framework_Firebase Authentication_Google Signin - Fatal编程技术网

ionic重定向问题中的angular firebase auth Signin WithRedirect

ionic重定向问题中的angular firebase auth Signin WithRedirect,angular,ionic-framework,firebase-authentication,google-signin,Angular,Ionic Framework,Firebase Authentication,Google Signin,我有一个需要谷歌登录的爱奥尼亚应用程序。 守则如下: import { AngularFireAuth } from 'angularfire2/auth'; import * as firebase from 'firebase/app'; import AuthProvider = firebase.auth.AuthProvider; constructor( private storage: Storage, private plt: Platform,

我有一个需要谷歌登录的爱奥尼亚应用程序。 守则如下:

import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';
import AuthProvider = firebase.auth.AuthProvider;
constructor(
        private storage: Storage,
        private plt: Platform,
        private afAuth: AngularFireAuth
    ) {
        afAuth.authState.subscribe(user => {
            this.user = user;
        });
        this.plt.ready().then(() => this.checkToken());
    }
private oauthSignIn(provider: AuthProvider) {
        if (!(<any>window).cordova) {
            return this.afAuth.auth.signInWithPopup(provider).then(res => {
                this.storage
                    .set(TOKEN_KEY, res.user.refreshToken)
                    .then(result => {
                        this.authenticationState.next(true);
                    });
            });
        } else {
            return this.afAuth.auth.signInWithRedirect(provider).then(() => {
                return this.afAuth.auth
                    .getRedirectResult()
                    .then(result => {
                        console.log(result);
                        const that = this;
                        this.storage
                            .set(TOKEN_KEY, result.user.refreshToken)
                            .then(res => {
                                that.authenticationState.next(true);
                            });
                    })
                    .catch(function(error) {
                        alert(error.message);
                    });
            });
        }
    }
从'angularfire2/auth'导入{AngularFireAuth};
从“firebase/app”导入*作为firebase;
导入AuthProvider=firebase.auth.AuthProvider;
建造师(
私有存储:存储,
私人plt:平台,
私人afAuth:AngularFireAuth
) {
afAuth.authState.subscribe(用户=>{
this.user=用户;
});
this.plt.ready()。然后(()=>this.checkToken());
}
专用oauthSignIn(提供程序:AuthProvider){
如果(!(窗口).cordova){
返回此.afAuth.auth.signInWithPopup(提供程序)。然后(res=>{
这是储藏室
.set(令牌\密钥,res.user.refreshToken)
。然后(结果=>{
this.authenticationState.next(true);
});
});
}否则{
返回此.afAuth.auth.signInWithRedirect(提供程序)。然后(()=>{
返回this.afAuth.auth
.getRedirectResult()
。然后(结果=>{
控制台日志(结果);
常数=this;
这是储藏室
.set(令牌\密钥,结果.user.refreshToken)
。然后(res=>{
that.authenticationState.next(true);
});
})
.catch(函数(错误){
警报(错误消息);
});
});
}
}
在这里,
signinwhithpopup
可以工作,但不能
signinwhithredirect

我在浏览器中检查了这个,我得到了用户信息和所有信息

但是没有关于后一个
功能的信息,这是我单独检查的

但真正的问题是, 一旦授予权限,这两种方法都不会重定向到应用程序页面

第二种方法是在单击登录后在mobile中打开浏览器。 但是重定向回浏览器而不是应用程序

第一个if语句也是如此

请帮我解决这个问题


如果需要更多详细信息,我将为您提供。

之所以会这样,是因为应用程序应该监视链接重定向。因为
signInWithRedirect
方法重定向到在Firebase控制台注册的链接。因此,如果当前URL是注册的重定向uri,则需要一个技巧来监视浏览器


实现这一点的方法是。基本上你应该安装通用链接和其他一些Cordova插件。

如果你想在登录后重定向页面,那么你可以使用这个

this.fAuth.authState
        .subscribe(
          user => {
            if (user) {
              this.rootPage = HomePage;
            } else {
              this.rootPage = LoginPage;
            }
          },
          () => {
            this.rootPage = LoginPage;
          }
        );

把这段代码放在app.component.ts文件中

基本上我没有得到这里提到的任何答案,而且@luis所说的可能是正确的,它对我不起作用

所以我决定在ionic中使用google plus插件,这对我来说很有帮助。

但问题不在于signinwithredirect,弹出式方法也是如此。您能解释一下提到的插件吗?