From f47bed7c378c978859a2a27fb30412360c82b68c Mon Sep 17 00:00:00 2001 From: migbash <20924663+migbash@users.noreply.github.com> Date: Tue, 24 Jan 2023 19:39:42 +0000 Subject: [PATCH] issue #1004 --- .../components/_main_/auth/Auth_Widget.svelte | 147 ++++++++++++++---- 1 file changed, 120 insertions(+), 27 deletions(-) diff --git a/src/lib/components/_main_/auth/Auth_Widget.svelte b/src/lib/components/_main_/auth/Auth_Widget.svelte index 3d306eb1a..c26ac9240 100644 --- a/src/lib/components/_main_/auth/Auth_Widget.svelte +++ b/src/lib/components/_main_/auth/Auth_Widget.svelte @@ -14,7 +14,7 @@ COMPONENT JS (w/ TS) import { userBetarenaSettings, type Scores_User } from '$lib/store/user-settings'; import { getMoralisAuth } from '@moralisweb3/client-firebase-auth-utils'; import { signInWithMoralis } from '@moralisweb3/client-firebase-evm-auth'; - import { GithubAuthProvider, GoogleAuthProvider, isSignInWithEmailLink, sendSignInLinkToEmail, signInWithCustomToken, signInWithEmailLink, signInWithPopup, type User } from "firebase/auth"; + import { fetchSignInMethodsForEmail, GithubAuthProvider, GoogleAuthProvider, isSignInWithEmailLink, sendSignInLinkToEmail, signInWithCustomToken, signInWithEmailLink, signInWithPopup, type User } from "firebase/auth"; import discord_icon from './assets/discord.svg'; import email_verify from './assets/email-verify.svg'; @@ -45,6 +45,8 @@ COMPONENT JS (w/ TS) let web3_wallet_address: string; let success_auth: boolean = false; let error_auth: boolean = false; + let email_error_format: boolean = false; + let email_already_in_use: boolean = false; const actionCodeSettings = { // [ℹ] URL / DOMAIN you want to redirect back to. @@ -109,26 +111,59 @@ COMPONENT JS (w/ TS) } } + async function check_email_user_exists (email_input: string) { + + } + async function login_with_email_link () { // DOC: https://firebase.google.com/docs/auth/web/email-link-auth?hl=en&authuser=0 try { + email_error_format = false processing = true // [🐞] if (dev) console.log('email_input', email_input) + await fetchSignInMethodsForEmail( + auth, + email_input + ) + .then((signInMethods) => { + if (signInMethods.length) { + // [ℹ] The email already exists in the Auth database. You can check the + // [ℹ] sign-in methods associated with it by checking signInMethods array. + // [ℹ] Show the option to sign in with that sign-in method. + email_already_in_use = true; + } else { + // [ℹ] User does not exist. Ask user to sign up. + email_already_in_use = false; + } + }) + .catch((error) => { + // Some error occurred. + }); + // [ℹ] validation + if (email_already_in_use) { + if (dev) console.log('🟠 Exit MagicLink') + processing = false + error_auth = true + setTimeout(() => { + error_auth = false + }, 1500) + return + } + // [ℹ] cont. send email await sendSignInLinkToEmail( auth, email_input, actionCodeSettings ) .then(() => { - // NOTE: The link was successfully sent - (custom) UI update + // [ℹ] The link was successfully sent - (custom) UI update processing = false auth_view = false email_verify_process = true - // NOTE: Save the email in localStroage() - // NOTE: if they open the link on the same device. + // [ℹ] Save the email in localStroage() for retrival on same device window.localStorage.setItem('emailForSignIn', email_input); - // NOTE: listen for email deep link cont. + // NOTE: listen for email deep link continued }) .catch((error) => { // TODO: Error Authetication Handle @@ -352,6 +387,15 @@ COMPONENT JS (w/ TS) function close_email_sent_view () { $sessionStore.auth_show = false email_verify_process = false + auth_view = true + } + + function wrong_email_format () { + email_error_format = true + error_auth = true + setTimeout(() => { + error_auth = false + }, 1500) } // ~~~~~~~~~~~~~~~~~~~~~ @@ -422,6 +466,7 @@ COMPONENT HTML {#if $sessionStore.auth_show}
$sessionStore.auth_show = false} in:fade /> {/if} @@ -557,7 +602,7 @@ COMPONENT HTML
- youremail@gmail.com. + {email_input}
Please verify your email to continue. @@ -566,7 +611,10 @@ COMPONENT HTML [ℹ] verify email to my inbox -->

open_email()}> Go to my inbox @@ -579,7 +627,10 @@ COMPONENT HTML style="margin-top: 24px;"> Did not get the email? login_with_email_link()}> Resend email @@ -643,26 +694,57 @@ COMPONENT HTML Enter your email address to sign up {/if}

- - + btn-primary + " + type="submit"> +

+ Continue with email +

+ +