Skip to content

[Auth] Fix bug in Auth where emailVerified wasn't set in the user constructor #5511

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 2 commits into from
Sep 17, 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
5 changes: 5 additions & 0 deletions .changeset/curly-elephants-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/auth": patch
---

Fix bug with the user `emailVerified` field persistence across tabs
3 changes: 3 additions & 0 deletions packages/auth/src/core/user/user_impl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe('core/user/user_impl', () => {
stsTokenManager,
displayName: 'displayName',
email: 'email',
emailVerified: true,
phoneNumber: 'phoneNumber',
photoURL: 'photoURL'
});
Expand All @@ -73,6 +74,7 @@ describe('core/user/user_impl', () => {
expect(user.email).to.eq('email');
expect(user.phoneNumber).to.eq('phoneNumber');
expect(user.photoURL).to.eq('photoURL');
expect(user.emailVerified).to.be.true;
});

it('sets optional fields to null if not provided', () => {
Expand All @@ -81,6 +83,7 @@ describe('core/user/user_impl', () => {
expect(user.email).to.eq(null);
expect(user.phoneNumber).to.eq(null);
expect(user.photoURL).to.eq(null);
expect(user.emailVerified).to.be.false;
});
});

Expand Down
1 change: 1 addition & 0 deletions packages/auth/src/core/user/user_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export class UserImpl implements UserInternal {
this.accessToken = stsTokenManager.accessToken;
this.displayName = opt.displayName || null;
this.email = opt.email || null;
this.emailVerified = opt.emailVerified || false;
this.phoneNumber = opt.phoneNumber || null;
this.photoURL = opt.photoURL || null;
this.isAnonymous = opt.isAnonymous || false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,9 @@ class BrowserLocalPersistence

constructor() {
super(window.localStorage, PersistenceType.LOCAL);
this.boundEventHandler = this.onStorageEvent.bind(this);
}

private readonly boundEventHandler: (
event: StorageEvent,
poll?: boolean
) => void;
private readonly boundEventHandler = (event: StorageEvent, poll?: boolean): void => this.onStorageEvent(event, poll);
private readonly listeners: Record<string, Set<StorageEventListener>> = {};
private readonly localCache: Record<string, string | null> = {};
// setTimeout return value is platform specific
Expand Down Expand Up @@ -88,7 +84,7 @@ class BrowserLocalPersistence
}
}

private onStorageEvent(event: StorageEvent, poll: boolean = false): void {
private onStorageEvent(event: StorageEvent, poll = false): void {
// Key would be null in some situations, like when localStorage is cleared
if (!event.key) {
this.forAllChangedKeys(
Expand Down