Skip to content

Commit f7d8324

Browse files
authored
[Auth] Switch compat UserCredential function to use promise chaining instead of async/await (#5562)
* Update user_credential converter function to use .then chaining instead of async/await * Formatting * Changeset
1 parent 91117e0 commit f7d8324

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

.changeset/tame-owls-deny.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@firebase/auth-compat": patch
3+
"@firebase/auth": patch
4+
---
5+
6+
Bugfix

packages/auth-compat/src/user_credential.ts

+28-27
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ function credentialFromResponse(
3131
function attachExtraErrorFields(auth: exp.Auth, e: FirebaseError): void {
3232
// The response contains all fields from the server which may or may not
3333
// actually match the underlying type
34-
const response = ((e.customData as exp.TaggedWithTokenResponse | undefined)
35-
?._tokenResponse as unknown) as Record<string, string>;
34+
const response = (e.customData as exp.TaggedWithTokenResponse | undefined)
35+
?._tokenResponse as unknown as Record<string, string>;
3636
if (e.code === 'auth/multi-factor-auth-required') {
3737
const mfaErr = e as compat.MultiFactorError;
3838
mfaErr.resolver = new MultiFactorResolver(
@@ -54,9 +54,9 @@ function attachExtraErrorFields(auth: exp.Auth, e: FirebaseError): void {
5454
function credentialFromObject(
5555
object: FirebaseError | exp.UserCredential
5656
): exp.AuthCredential | null {
57-
const { _tokenResponse } = (object instanceof FirebaseError
58-
? object.customData
59-
: object) as exp.TaggedWithTokenResponse;
57+
const { _tokenResponse } = (
58+
object instanceof FirebaseError ? object.customData : object
59+
) as exp.TaggedWithTokenResponse;
6060
if (!_tokenResponse) {
6161
return null;
6262
}
@@ -138,31 +138,32 @@ function credentialFromObject(
138138
: provider.credentialFromResult(object);
139139
}
140140

141-
export async function convertCredential(
141+
export function convertCredential(
142142
auth: exp.Auth,
143143
credentialPromise: Promise<exp.UserCredential>
144144
): Promise<compat.UserCredential> {
145-
let credential: exp.UserCredential;
146-
try {
147-
credential = await credentialPromise;
148-
} catch (e) {
149-
if (e instanceof FirebaseError) {
150-
attachExtraErrorFields(auth, e);
151-
}
152-
throw e;
153-
}
154-
const { operationType, user } = credential;
155-
156-
return {
157-
operationType,
158-
credential: credentialFromResponse(
159-
credential as exp.UserCredentialInternal
160-
),
161-
additionalUserInfo: exp.getAdditionalUserInfo(
162-
credential as exp.UserCredential
163-
),
164-
user: User.getOrCreate(user)
165-
};
145+
return credentialPromise
146+
.catch(e => {
147+
if (e instanceof FirebaseError) {
148+
attachExtraErrorFields(auth, e);
149+
}
150+
throw e;
151+
})
152+
.then(credential => {
153+
const operationType = credential.operationType;
154+
const user = credential.user;
155+
156+
return {
157+
operationType,
158+
credential: credentialFromResponse(
159+
credential as exp.UserCredentialInternal
160+
),
161+
additionalUserInfo: exp.getAdditionalUserInfo(
162+
credential as exp.UserCredential
163+
),
164+
user: User.getOrCreate(user)
165+
};
166+
});
166167
}
167168

168169
export async function convertConfirmationResult(

0 commit comments

Comments
 (0)