Skip to content

[Auth] Make anonymous sign in wait for auth to finish initializing #4963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2021
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);
});
});