Reputation: 3510
I've been running this Angular 5 app for a while with Google authentication and then this error suddenly appeared (both on prod and dev). Sign in is successful and I am getting a GoogleAuth object (I can get the user details), but then I get this error:
Uncaught TypeError: googleAuth.then is not a function
Here's the code block. _googleAuth is a service which calls 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()) {
...
}
...
I've updated the typings to:
"@types/gapi": "0.0.35", "@types/gapi.auth2": "0.0.47",
Here's the getAuth function (which seems to still work):
public getAuth(): Observable<GoogleAuth> {
if (!this.GoogleAuth) {
return this.googleApi.onLoad().mergeMap(() => this.loadGapiAuth());
}
return Observable.of(this.GoogleAuth);
}
I've checked the typings and GoogleAuth.then is defined there. Why is it that I can get a GoogleAuth object but not call .then?
The Google docs for GoogleAuth.then are here: https://developers.google.com/identity/sign-in/web/reference#googleauththenoninit-onerror
Upvotes: 0
Views: 1239
Reputation: 3510
I'm still not clear why this became an error now, but I found a possible solution. The TypeScript wrapper service was already calling .then after gapi.auth2.init, so it looks like I was calling it twice. I've removed that check and it seems to be working. I still have to run my test suite, but so far it looks promising.
Upvotes: 1