Skip to content

Commit

Permalink
[Auth] Fix bug in Auth where emailVerified wasn't set in the user con…
Browse files Browse the repository at this point in the history
…structor (#5511)

* Fix bug in Auth where emailVerified wasn't set in the user constructor

* Add changeset
  • Loading branch information
sam-gc authored Sep 17, 2021
1 parent b83591e commit a5d87bc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
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

0 comments on commit a5d87bc

Please sign in to comment.