Open RezaRahmati opened 3 years ago
Facing similar issue, any update on this bug report? currently on version 9.1.0-rc.8
I extended the original class with the refresh implemented, they didn't had implemented it
import { Injectable } from '@angular/core';
import firebase from 'firebase/compat/app';
import { Observable, of as observableOf, from } from 'rxjs';
import { catchError, map, switchMap, take } from 'rxjs/operators';
import { NbAuthStrategyOptions, NbAuthStrategyClass, NbAuthResult } from '@nebular/auth';
import { NbFirebaseBaseStrategy, NbFirebaseIdentityProviderStrategyOptions } from '@nebular/firebase-auth';
@Injectable()
export class FirebaseGoogleStrategy extends NbFirebaseBaseStrategy {
protected defaultOptions: NbFirebaseIdentityProviderStrategyOptions = new NbFirebaseIdentityProviderStrategyOptions();
static setup(options: NbFirebaseIdentityProviderStrategyOptions): [NbAuthStrategyClass, NbAuthStrategyOptions] {
return [FirebaseGoogleStrategy, options];
}
authenticate(data?: any): Observable<NbAuthResult> {
const module = 'authenticate';
const provider = new firebase.auth.GoogleAuthProvider();
const scopes = this.getOption('scopes');
scopes.forEach((scope) => provider.addScope(scope));
provider.setCustomParameters(this.getOption('customParameters'));
return from(this.afAuth.signInWithPopup(provider)).pipe(
switchMap((res) => this.processSuccess(res, module)),
catchError((error) => this.processFailure(error, module)),
);
}
refreshToken(data?: any): Observable<NbAuthResult> {
const module = 'refreshToken';
return this.afAuth.authState.pipe(
take(1),
switchMap((user) => {
if (user == null) {
return observableOf(
new NbAuthResult(false, null, null, [
"There is no logged in user so refresh of id token isn't possible",
]),
);
}
return this.refreshIdToken(user, module);
}),
);
}
protected refreshIdToken(user: firebase.User, module): Observable<NbAuthResult> {
return from(user.getIdToken(true)).pipe(
map((token) => {
return new NbAuthResult(
true,
null,
this.getOption(`${module}.redirect.success`),
[],
this.getOption(`${module}.defaultMessages`),
this.createToken(token),
);
}),
catchError((error) => this.processFailure(error, module)),
);
}
}
Issue type
I'm submitting a ... (check one with "x")
Issue description
Current behavior:
Throwing error
Error: 'refreshToken' is not supported by 'NbFirebaseGoogleStrategy', use 'authenticate'
While if you autheticate without nebular with AngularFire this problem doesn't happen, and I think it could be related to this https://stackoverflow.com/a/37908468/2279488
Expected behavior:
Token doesn't expire until user signed out
Steps to reproduce:
this.authService.isAuthenticatedOrRefresh()
in authGuardRelated code:
Other information:
npm, node, OS, Browser
Angular, Nebular