From c5d3a1ea09810ebde661d5610463e423f1ae2cd0 Mon Sep 17 00:00:00 2001 From: Dovi Cowan Date: Wed, 1 Nov 2023 23:41:39 +0000 Subject: [PATCH] email verification --- src/routes/EmailVerify.svelte | 62 +++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/src/routes/EmailVerify.svelte b/src/routes/EmailVerify.svelte index bd92406..429154b 100644 --- a/src/routes/EmailVerify.svelte +++ b/src/routes/EmailVerify.svelte @@ -1,3 +1,61 @@ \ No newline at end of file + import { navigate } from "svelte-navigator/src/history"; + import { account, loggedInUser, teams } from "../lib/appwrite"; + import Header from "../lib/Header.svelte"; + import { Link } from "svelte-navigator"; + + const searchParams = new URLSearchParams(document.location.search); + + let confirmed = false; + let alreadyConfirmed = false; + + if ( + loggedInUser !== null && + searchParams.get("userId") == loggedInUser["$id"] + ) { + account + .updateVerification( + searchParams.get("userId"), + searchParams.get("secret"), + ) + .then((r) => { + console.log(r); + confirmed = true; + }) + .catch((r) => { + if (r.type == "user_invalid_token") { + alreadyConfirmed = true; + } + }); + } + + +
+ {#if loggedInUser !== null} +
+ {/if} + + {#if loggedInUser == null} + Please log in to confirm your email address Log in + {/if} + + {#if loggedInUser !== null && searchParams.get("userId") !== loggedInUser["$id"]} + You can't verify your email for a different account. Please log out and log + back into the correct user. + {/if} + + {#if confirmed == true} + Your email address has been successfully confirmed! Go home + {/if} + + {#if alreadyConfirmed == true} + This verification link is invalid. You may already used it, or it may have + expired. Go home + {/if} +