Created
October 4, 2023 16:39
-
-
Save YonatanKra/c25586744858cbe7350522eea9a40aca to your computer and use it in GitHub Desktop.
Tauri-demo: refactor the login method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async #isUserRegistered(email: string) { | |
const signInMethods = await fetchSignInMethodsForEmail(getAuth(), email); | |
return signInMethods.length > 0; | |
} | |
async #registerUser(email: string, password: string) { | |
await createUserWithEmailAndPassword(getAuth(), email, password); | |
await sendEmailVerification(getAuth().currentUser!); | |
} | |
async login(email: string, password: string) { | |
if (await this.#isUserRegistered(email) === false) { | |
await this.#registerUser(email, password); | |
} else { | |
await signInWithEmailAndPassword(getAuth(), email, password); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment