Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages-exp/auth-exp/src/core/strategies/anonymous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { _castAuth } from '../auth/auth_impl';
*/
export async function signInAnonymously(auth: Auth): Promise<UserCredential> {
const authInternal = _castAuth(auth);
await authInternal._initializationPromise;
if (authInternal.currentUser?.isAnonymous) {
// If an anonymous user is already signed in, no need to sign them in again.
return new UserCredentialImpl({
Expand Down
15 changes: 15 additions & 0 deletions packages-exp/auth-exp/test/integration/webdriver/anonymous.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,19 @@ browserDescribe('WebDriver anonymous auth test', driver => {
);
expect(after.uid).to.eq(before.uid);
});

it('user persists after refresh and sign in (no init wait)', async () => {
const { user: before }: UserCredential = await driver.call(
AnonFunction.SIGN_IN_ANONYMOUSLY
);
await driver.webDriver.navigate().refresh();
await driver.injectConfigAndInitAuth();

// At this point we aren't waiting for auth to "settle"
// Sign in before the first onAuthStateChanged has occurred
const { user: after }: UserCredential = await driver.call(
AnonFunction.SIGN_IN_ANONYMOUSLY
);
expect(after.uid).to.eq(before.uid);
});
});