angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

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

Open nas398 opened this issue 3 years ago • 4 comments
trafficstars

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" },

nas398 avatar Jun 05 '22 10:06 nas398

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

google-oss-bot avatar Jun 05 '22 10:06 google-oss-bot

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?

jamesdaniels avatar Jun 06 '22 16:06 jamesdaniels

@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..

nas398 avatar Jun 07 '22 11:06 nas398

@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.

geromegrignon avatar Jun 13 '22 10:06 geromegrignon