Skip to content

Commit 09cc4aa

Browse files
committed
Add beforeAuthStateChanged fn export
1 parent fc38643 commit 09cc4aa

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

common/api-review/auth.api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ export interface AuthSettings {
242242
appVerificationDisabledForTesting: boolean;
243243
}
244244

245+
// @public
246+
export function beforeAuthStateChanged(auth: Auth, callback: (user: User | null) => void | Promise<void>, onAbort?: () => void): Unsubscribe;
247+
245248
// @public
246249
export const browserLocalPersistence: Persistence;
247250

packages/auth/src/core/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,26 @@ export function onIdTokenChanged(
8383
completed
8484
);
8585
}
86+
/**
87+
* Adds a blocking callback that runs before an auth state change
88+
* sets a new user.
89+
*
90+
* @param auth - The {@link Auth} instance.
91+
* @param callback - callback triggered before new user value is set.
92+
* If this throws, it will block the user from being set.
93+
* @param onAbort - callback triggered if a later before state changed
94+
* callback throws, allowing you to undo any side effects.
95+
*/
96+
export function beforeAuthStateChanged(
97+
auth: Auth,
98+
callback: (user: User|null) => void | Promise<void>,
99+
onAbort?: () => void,
100+
): Unsubscribe {
101+
return getModularInstance(auth).beforeAuthStateChanged(
102+
callback,
103+
onAbort
104+
);
105+
}
86106
/**
87107
* Adds an observer for changes to the user's sign-in state.
88108
*

0 commit comments

Comments
 (0)