Skip to content

Commit

Permalink
Remove the deprecated fetchSignInMethodsForEmail function
Browse files Browse the repository at this point in the history
  • Loading branch information
GogoVega committed Aug 18, 2024
1 parent cc5d5d4 commit 261a1ec
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/lib/firebase/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
Auth,
UserCredential,
createUserWithEmailAndPassword,
fetchSignInMethodsForEmail,
getAuth,
signInAnonymously,
signInWithCustomToken,
Expand Down Expand Up @@ -107,23 +106,32 @@ export class Client extends TypedEmitter<ClientEvents> {
createUser?: boolean
): Promise<UserCredential> {
return this.wrapSignIn(async () => {
// Checks if the user already has an account otherwise it creates one
const method = await fetchSignInMethodsForEmail(this._auth as Auth, email);
try {
// Try to sign in
const user = await signInWithEmailAndPassword(this._auth as Auth, email, password);
return user;
} catch (error) {
if (error instanceof FirebaseError && error.code === "auth/wrong-password") {
throw error;
}

if (error instanceof FirebaseError && error.code === "auth/user-not-found") {
if (!createUser) {
throw new FirebaseError("auth/unknown-email", "Unknown email");
}

if (method.length === 0 && createUser) {
const user = await createUserWithEmailAndPassword(this._auth as Auth, email, password);
const user = await createUserWithEmailAndPassword(this._auth as Auth, email, password);

if (this.warn) {
this.warn(
`The user "${email}" has been successfully created. You can delete it in the Authenticate section if it is an error.`
);
if (this.warn) {
this.warn(
`The user "${email}" has been successfully created. You can delete it in the Authenticate section if it is an error.`
);
}

return user;
}

return user;
} else if (method.includes("password")) {
return signInWithEmailAndPassword(this._auth as Auth, email, password);
} else {
throw new FirebaseError("auth/unknown-email", "Unknown email");
throw error;
}
});
}
Expand Down

0 comments on commit 261a1ec

Please sign in to comment.