angular / angularfire

Angular + Firebase = ❤️
https://firebaseopensource.com/projects/angular/angularfire2
MIT License
7.7k stars 2.19k forks source link

Angualr 6 web app log out user when app launch with bad internet #3233

Open nas398 opened 2 years ago

nas398 commented 2 years ago

Sometimes when my app launch with a bad internet connection the user got logged out.. I don't want this to happen.. I want the user to continue being logged in even if the app didn't launched properly because of bad internet connection..

"@angular/fire": "^5.1.0", I attached my AuthService code, also my dependencies.. what I am doing wrong?

import { Router } from '@angular/router';
import { Injectable } from '@angular/core';
import { AngularFireAuth } from '@angular/fire/auth';
import { Observable } from 'rxjs/Observable';
import { Subject } from 'rxjs/Subject';

@Injectable()
export class AuthService {
  private user: Observable<firebase.User>;
  public userDetails: firebase.User = null;
  userAuthDoneSubject = new Subject();

  constructor(
    private firebaseAuth: AngularFireAuth) {
    this.user = firebaseAuth.authState;

    this.user.subscribe(
      (userDetails) => {
        if (userDetails) {
          this.userDetails = userDetails;
        }
        else {
          this.userDetails = null;
        }
        this.userAuthDoneSubject.next();
      },(error) => {this.userAuthDoneSubject.error("AuthService:error authenticate"); }
    );
  }
  isLoggedIn() {
    if (this.userDetails == null ) {
      return false;
    } else {
        return true;
      }
    }

    logout() {
       return this.firebaseAuth.auth.signOut();
    }

  signinUser(customToken:any){
    return this.firebaseAuth.auth.signInWithCustomToken(customToken)
  }

  getJWT() {
    return this.firebaseAuth.auth.currentUser.getIdToken(true);
  }

}

"dependencies": { "@agm/core": "^1.0.0", "@angular/animations": "^6.1.0", "@angular/common": "^6.1.0", "@angular/compiler": "^6.1.0", "@angular/core": "^6.1.0", "@angular/fire": "^5.1.0", "@angular/forms": "^6.1.0", "@angular/http": "^6.1.0", "@angular/platform-browser": "^6.1.0", "@angular/platform-browser-dynamic": "^6.1.0", "@angular/router": "^6.1.0", "@types/googlemaps": "^3.30.19", "angular2-multiselect-dropdown": "^4.6.2", "core-js": "^2.5.4", "css-toggle-switch": "^4.1.0", "firebase": "^5.5.9", "ng-lazyload-image": "^6.1.0", "ngx-owl-carousel-o": "^0.1.2", "ngx-page-scroll-core": "^6.0.2", "rxjs": "^6.0.0", "rxjs-compat": "^6.3.3", "zone.js": "~0.8.26" },

google-oss-bot commented 2 years ago

This issue does not seem to follow the issue template. Make sure you provide all the required information.

jamesdaniels commented 2 years ago

It immediately strikes me that you're forcing refresh by passing true to getIdToken, if you drop that and just call getIdToken() does that help?

nas398 commented 2 years ago

@jamesdaniels no it does not help.. actually getIdToken() is not in use anymore.. I think there should be a setting to prevent logout if it fail to refresh the token..

geromegrignon commented 2 years ago

@jamesdaniels no it does not help.. actually getIdToken() is not in use anymore.. I think there should be a setting to prevent logout if it fail to refresh the token..

It would be a major security vulnerability.