Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 5e0ddd4

Browse files
committed
[auth] - Replicate web onAuthChanged() behavior by immediately calling the callback handler with the currentUser
Previously the callback handler would be called only when we have an auth state update, but the web api's behavior is to call the handler once onAuthChanged() is attached. The initial value would then be undefined if the user was never logged in.
1 parent 67a8f98 commit 5e0ddd4

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/app/auth/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,12 @@ export namespace auth {
4444
}
4545

4646
// Completed will never be called, but it is here to closely follow the web api interface.
47+
// When called, the callback handler will be passed in the currentUser or undefined if not signed in
4748
public onAuthStateChanged(handler: (user: User) => void, error?: (err) => any, completed?: Unsubscribe): Unsubscribe {
4849
this.authStateChangedHandler = handler;
4950
if (error) this.authStateOnErrorHandler = error;
5051
console.log(">> added onAuthStateChanged handler");
51-
52+
handler(this.currentUser);
5253
return () => {
5354
this.authStateChangedHandler = undefined;
5455
this.authStateOnErrorHandler = undefined;

0 commit comments

Comments
 (0)