I am using @angular/fire
in my project to use firebase. To test the integration with firebase services I run firebase emulators: start
in the command line. While serving the angular application with ng serve --open
whenever I make changes and save any file the page reloads and I am automatically signed out of the Firebase account. This happens only while using Firebase Emulators. I don't know whether this is an issue with @angular/fire
or firebase auth emulator. This is very frustrating as I need to sign in on every file change in the angular app.
My App.module.ts has the following configuration for providers. Whenever I login
providers: [
{
provide: USE_AUTH_EMULATOR,
useValue: environment.useEmulators ? ["localhost", 9099] : undefined,
},
{
provide: USE_DATABASE_EMULATOR,
useValue: environment.useEmulators ? ["localhost", 9000] : undefined,
},
{
provide: USE_FIRESTORE_EMULATOR,
useValue: environment.useEmulators ? ["localhost", 8080] : undefined,
},
{
provide: USE_FUNCTIONS_EMULATOR,
useValue: environment.useEmulators ? ["localhost", 5001] : undefined,
},
],
Edit-1: I check whether a user is signed in or not by injecting AngularFireAuth
in the constructor of a global service.
constructor(
public firebaseAuth: AngularFireAuth
) {
firebaseAuth.authState.subscribe(user => {
console.log(user,"in authServices");
this.authChange.next(user);
})
}
Once I sign in it returns a non-null user but If I change a file(or just reload the page) and save it the page reloads and the user received in the subscription callback is null.
Edit-2: After I sign-in I receive the below data for the user
in the authState
subscription callback.
Jm {G: Array(0), l: "AIzaSyDTWKynj8jL3hnLPP0Fe_uY-j4vKR4Ozf0", m: "[DEFAULT]", o: "workern-tester.firebaseapp.com", a: Ji, …}$: ƒ ()$b: Jm {G: Array(0), l: "AIzaSyDTWKynj8jL3hnLPP0Fe_uY-j4vKR4Ozf0", m: "[DEFAULT]", o: "workern-tester.firebaseapp.com", a: Ji, …}Aa: ƒ (f)Ba: ƒ (f)G: []N: um {a: Jm, b: Array(0), enrolledFactors: Array(0), c: ƒ}P: trueR: [ƒ]W: Fn {m: false, settings: fm, app: FirebaseAppImpl, a: Ji, R: Array(0), …}X: ["FirebaseUI-web"]a: Ji {c: "AIzaSyDTWKynj8jL3hnLPP0Fe_uY-j4vKR4Ozf0", l: "http://localhost:9099/securetoken.googleapis.com/v1/token", v: Ze, g: {…}, h: "http://localhost:9099/www.googleapis.com/identitytoolkit/v3/relyingparty/", …}aa: Fn {m: false, settings: fm, app: FirebaseAppImpl, a: Ji, R: Array(0), …}b: Bm {c: Ji, a: "MEmI8VAJA36h8ATV3o57OzoWemszZHMgmWA2pH2RZFkpqvQ4nA…To3w5TfWh2y0iWW4n-xJfiVfmrLBudZt8qvtNcb_UNLmYExZQ", b: ig}ba: Fn {m: false, settings: fm, app: FirebaseAppImpl, a: Ji, R: Array(0), …}displayName: nullemail: nullemailVerified: falsef: nullfb: nullha: tn {a: "AIzaSyDTWKynj8jL3hnLPP0Fe_uY-j4vKR4Ozf0:[DEFAULT]", b: Uk}i: Hl {i: {…}, u: 0, O: "workern-tester.firebaseapp.com", m: "AIzaSyDTWKynj8jL3hnLPP0Fe_uY-j4vKR4Ozf0", v: "[DEFAULT]", …}isAnonymous: falsel: "AIzaSyDTWKynj8jL3hnLPP0Fe_uY-j4vKR4Ozf0"m: "[DEFAULT]"metadata: Gm {a: "1606683443096", b: "1606712979911", lastSignInTime: "Mon, 30 Nov 2020 05:09:39 GMT", creationTime: "Sun, 29 Nov 2020 20:57:23 GMT"}multiFactor: um {a: Jm, b: Array(0), enrolledFactors: Array(0), c: ƒ}o: "workern-tester.firebaseapp.com"oa: undefinedpa: nullphoneNumber: "+917566675092"photoURL: nullproviderData: [Im]refreshToken: "MEmI8VAJA36h8ATV3o57OzoWemszZHMgmWA2pH2RZFkpqvQ4nA-u2MrzglVSO6e-_c4m9SdXDF9r1oiDWGrz7_UDP6ZxjdIatwf4OUCVGIo1o-d9z4dK7hmG4Q1n-tTmsgKb-vZNQ3SIUQ4ar1uYI8Jq3tgTo3w5TfWh2y0iWW4n-xJfiVfmrLBudZt8qvtNcb_UNLmYExZQ"tenantId: nullu: ym {c: 30000, f: 960000, h: ƒ, i: ƒ, g: ƒ, …}uid: "6e555FSHWBGj5jQKn28yilNC7cO1"v: hd {src: Jm, a: {…}, b: 4}xa: falseya: "eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJwaG9uZV9udW1iZXIiOiIrOTE3NTY2Njc1MDkyIiwiYXV0aF90aW1lIjoxNjA2NzEyOTc5LCJ1c2VyX2lkIjoiNmU1NTVGU0hXQkdqNWpRS24yOHlpbE5DN2NPMSIsImZpcmViYXNlIjp7ImlkZW50aXRpZXMiOnsicGhvbmUiOlsiKzkxNzU2NjY3NTA5MiJdfSwic2lnbl9pbl9wcm92aWRlciI6InBob25lIn0sImlhdCI6MTYwNjcxMjk3OSwiZXhwIjoxNjA2NzE2NTc5LCJhdWQiOiJ3b3JrZXJuLXRlc3RlciIsImlzcyI6Imh0dHBzOi8vc2VjdXJldG9rZW4uZ29vZ2xlLmNvbS93b3JrZXJuLXRlc3RlciIsInN1YiI6IjZlNTU1RlNIV0JHajVqUUtuMjh5aWxOQzdjTzEifQ."za: ƒ (f)_lat: "eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJwaG9uZV9udW1iZXIiOiIrOTE3NTY2Njc1MDkyIiwiYXV0aF90aW1lIjoxNjA2NzEyOTc5LCJ1c2VyX2lkIjoiNmU1NTVGU0hXQkdqNWpRS24yOHlpbE5DN2NPMSIsImZpcmViYXNlIjp7ImlkZW50aXRpZXMiOnsicGhvbmUiOlsiKzkxNzU2NjY3NTA5MiJdfSwic2lnbl9pbl9wcm92aWRlciI6InBob25lIn0sImlhdCI6MTYwNjcxMjk3OSwiZXhwIjoxNjA2NzE2NTc5LCJhdWQiOiJ3b3JrZXJuLXRlc3RlciIsImlzcyI6Imh0dHBzOi8vc2VjdXJldG9rZW4uZ29vZ2xlLmNvbS93b3JrZXJuLXRlc3RlciIsInN1YiI6IjZlNTU1RlNIV0JHajVqUUtuMjh5aWxOQzdjTzEifQ."__proto__: I "in authServices"
After I reload the page I receive the log shown below in the callback for the authState
subscription and this state doesn't change after a few moments.
null "in authServices"