Skip to content

Commit b046a61

Browse files
authored
Make anonymous sign in wait for auth to finish initializing (#4963)
1 parent 969d5e0 commit b046a61

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

packages-exp/auth-exp/src/core/strategies/anonymous.ts

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { _castAuth } from '../auth/auth_impl';
3434
*/
3535
export async function signInAnonymously(auth: Auth): Promise<UserCredential> {
3636
const authInternal = _castAuth(auth);
37+
await authInternal._initializationPromise;
3738
if (authInternal.currentUser?.isAnonymous) {
3839
// If an anonymous user is already signed in, no need to sign them in again.
3940
return new UserCredentialImpl({

packages-exp/auth-exp/test/integration/webdriver/anonymous.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,19 @@ browserDescribe('WebDriver anonymous auth test', driver => {
5252
);
5353
expect(after.uid).to.eq(before.uid);
5454
});
55+
56+
it('user persists after refresh and sign in (no init wait)', async () => {
57+
const { user: before }: UserCredential = await driver.call(
58+
AnonFunction.SIGN_IN_ANONYMOUSLY
59+
);
60+
await driver.webDriver.navigate().refresh();
61+
await driver.injectConfigAndInitAuth();
62+
63+
// At this point we aren't waiting for auth to "settle"
64+
// Sign in before the first onAuthStateChanged has occurred
65+
const { user: after }: UserCredential = await driver.call(
66+
AnonFunction.SIGN_IN_ANONYMOUSLY
67+
);
68+
expect(after.uid).to.eq(before.uid);
69+
});
5570
});

0 commit comments

Comments
 (0)