Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Created October 4, 2023 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YonatanKra/c25586744858cbe7350522eea9a40aca to your computer and use it in GitHub Desktop.
Save YonatanKra/c25586744858cbe7350522eea9a40aca to your computer and use it in GitHub Desktop.
Tauri-demo: refactor the login method
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