Skip to content

Commit a5d87bc

Browse files
authored
[Auth] Fix bug in Auth where emailVerified wasn't set in the user constructor (#5511)
* Fix bug in Auth where emailVerified wasn't set in the user constructor * Add changeset
1 parent b83591e commit a5d87bc

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

.changeset/curly-elephants-cover.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/auth": patch
3+
---
4+
5+
Fix bug with the user `emailVerified` field persistence across tabs

packages/auth/src/core/user/user_impl.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ describe('core/user/user_impl', () => {
6565
stsTokenManager,
6666
displayName: 'displayName',
6767
email: 'email',
68+
emailVerified: true,
6869
phoneNumber: 'phoneNumber',
6970
photoURL: 'photoURL'
7071
});
@@ -73,6 +74,7 @@ describe('core/user/user_impl', () => {
7374
expect(user.email).to.eq('email');
7475
expect(user.phoneNumber).to.eq('phoneNumber');
7576
expect(user.photoURL).to.eq('photoURL');
77+
expect(user.emailVerified).to.be.true;
7678
});
7779

7880
it('sets optional fields to null if not provided', () => {
@@ -81,6 +83,7 @@ describe('core/user/user_impl', () => {
8183
expect(user.email).to.eq(null);
8284
expect(user.phoneNumber).to.eq(null);
8385
expect(user.photoURL).to.eq(null);
86+
expect(user.emailVerified).to.be.false;
8487
});
8588
});
8689

packages/auth/src/core/user/user_impl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export class UserImpl implements UserInternal {
8383
this.accessToken = stsTokenManager.accessToken;
8484
this.displayName = opt.displayName || null;
8585
this.email = opt.email || null;
86+
this.emailVerified = opt.emailVerified || false;
8687
this.phoneNumber = opt.phoneNumber || null;
8788
this.photoURL = opt.photoURL || null;
8889
this.isAnonymous = opt.isAnonymous || false;

packages/auth/src/platform_browser/persistence/local_storage.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,9 @@ class BrowserLocalPersistence
5252

5353
constructor() {
5454
super(window.localStorage, PersistenceType.LOCAL);
55-
this.boundEventHandler = this.onStorageEvent.bind(this);
5655
}
5756

58-
private readonly boundEventHandler: (
59-
event: StorageEvent,
60-
poll?: boolean
61-
) => void;
57+
private readonly boundEventHandler = (event: StorageEvent, poll?: boolean): void => this.onStorageEvent(event, poll);
6258
private readonly listeners: Record<string, Set<StorageEventListener>> = {};
6359
private readonly localCache: Record<string, string | null> = {};
6460
// setTimeout return value is platform specific
@@ -88,7 +84,7 @@ class BrowserLocalPersistence
8884
}
8985
}
9086

91-
private onStorageEvent(event: StorageEvent, poll: boolean = false): void {
87+
private onStorageEvent(event: StorageEvent, poll = false): void {
9288
// Key would be null in some situations, like when localStorage is cleared
9389
if (!event.key) {
9490
this.forAllChangedKeys(

0 commit comments

Comments
 (0)