Skip to content

Commit eb663f2

Browse files
authored
Fix a couple of parity issues for auth-exp (#3878)
* Fix two parity bugs * Formatting
1 parent 791824b commit eb663f2

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

packages-exp/auth-exp/src/core/auth/auth_impl.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ describe('core/auth/auth_impl', () => {
150150
});
151151
});
152152

153+
it('waits for initialization for authStateChange', done => {
154+
const user = testUser(auth, 'uid');
155+
auth.currentUser = user;
156+
auth._isInitialized = false;
157+
auth._onAuthStateChanged(user => {
158+
expect(user).to.eq(user);
159+
done();
160+
});
161+
});
162+
153163
it('immediately calls idTokenChange if initialization finished', done => {
154164
const user = testUser(auth, 'uid');
155165
auth.currentUser = user;
@@ -160,6 +170,16 @@ describe('core/auth/auth_impl', () => {
160170
});
161171
});
162172

173+
it('waits for initialization for idTokenChanged', done => {
174+
const user = testUser(auth, 'uid');
175+
auth.currentUser = user;
176+
auth._isInitialized = false;
177+
auth._onIdTokenChanged(user => {
178+
expect(user).to.eq(user);
179+
done();
180+
});
181+
});
182+
163183
it('immediate callback is done async', () => {
164184
auth._isInitialized = true;
165185
let callbackCalled = false;

packages-exp/auth-exp/src/core/auth/auth_impl.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,18 @@ export class AuthImplCompat<T extends User> implements Auth, _FirebaseService {
357357
error?: ErrorFn,
358358
completed?: CompleteFn
359359
): Unsubscribe {
360-
if (this._isInitialized) {
361-
const cb =
362-
typeof nextOrObserver === 'function'
363-
? nextOrObserver
364-
: nextOrObserver.next;
365-
// The callback needs to be called asynchronously per the spec.
366-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
367-
Promise.resolve().then(() => cb(this.currentUser));
368-
}
360+
const cb =
361+
typeof nextOrObserver === 'function'
362+
? nextOrObserver
363+
: nextOrObserver.next;
364+
365+
const promise = this._isInitialized
366+
? Promise.resolve()
367+
: this._initializationPromise;
368+
assert(promise, AuthErrorCode.INTERNAL_ERROR, { appName: this.name });
369+
// The callback needs to be called asynchronously per the spec.
370+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
371+
promise.then(() => cb(this.currentUser));
369372

370373
if (typeof nextOrObserver === 'function') {
371374
return subscription.addObserver(nextOrObserver, error, completed);

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,20 +219,20 @@ export class UserImpl implements User {
219219
}
220220

221221
static _fromJSON(auth: Auth, object: PersistedBlob): User {
222+
const displayName = object.displayName ?? undefined;
223+
const email = object.email ?? undefined;
224+
const phoneNumber = object.phoneNumber ?? undefined;
225+
const photoURL = object.photoURL ?? undefined;
226+
const tenantId = object.tenantId ?? undefined;
227+
const _redirectEventId = object._redirectEventId ?? undefined;
228+
const createdAt = object.createdAt ?? undefined;
229+
const lastLoginAt = object.lastLoginAt ?? undefined;
222230
const {
223231
uid,
224-
email,
225232
emailVerified,
226-
displayName,
227233
isAnonymous,
228-
photoURL,
229-
phoneNumber,
230-
tenantId,
231234
providerData,
232-
stsTokenManager: plainObjectTokenManager,
233-
_redirectEventId,
234-
createdAt,
235-
lastLoginAt
235+
stsTokenManager: plainObjectTokenManager
236236
} = object;
237237

238238
assert(uid && plainObjectTokenManager, AuthErrorCode.INTERNAL_ERROR, {

0 commit comments

Comments
 (0)