未捕获的TypeError:googleAuth.then不是函数

问题描述 投票:-1回答:1

我已经运行这个Angular 5应用程序一段时间使用Google身份验证,然后突然出现此错误(在prod和dev上)。登录成功,我收到一个GoogleAuth对象(我可以获取用户详细信息),但后来我收到此错误:

Uncaught TypeError: googleAuth.then is not a function

这是代码块。 _googleAuth是一种调用init的服务。

this._googleAuth.getAuth()
      .subscribe(googleAuth => {

        // TODO
        console.log('user signedIn: ', googleAuth.isSignedIn.get()); // this returns true

        const self = this;
        googleAuth.then(function() { // error occurs here
          if (googleAuth.isSignedIn.get()) {
            ...
          } 
...

我把这些打字更新为:

“@ types / gap”:“0.0.35”,“@ types / gapi.auth2”:“0.0.47”,

这是getAuth函数(似乎仍然有效):

public getAuth(): Observable<GoogleAuth> {
        if (!this.GoogleAuth) {
            return this.googleApi.onLoad().mergeMap(() => this.loadGapiAuth());
        }
        return Observable.of(this.GoogleAuth);
    }

我检查了打字和GoogleAuth.then在那里定义。为什么我可以获得GoogleAuth对象但不能调用.then?

GoogleAuth.then的Google文档在这里:https://developers.google.com/identity/sign-in/web/reference#googleauththenoninit-onerror

javascript angular typescript google-api google-authentication
1个回答
0
投票

我现在还不清楚为什么这会成为一个错误,但我找到了一个可能的解决方案。 TypeScript包装器服务已经在gapi.auth2.init之后调用。所以看起来我正在调用它两次。我删除了那张支票,它似乎正在运作。我仍然需要运行我的测试套件,但到目前为止看起来很有希望。

© www.soinside.com 2019 - 2024. All rights reserved.