|
| 1 | +<script lang="ts"> |
| 2 | + import { useAuth } from "@mmailaender/convex-auth-svelte/sveltekit"; |
| 3 | +
|
| 4 | + const { signIn, isLoading } = useAuth(); |
| 5 | +
|
| 6 | + let step = $state<"forgot" | { email: string }>("forgot"); |
| 7 | +</script> |
| 8 | + |
| 9 | +<div class="hero bg-base-200 min-h-screen"> |
| 10 | + <div class="card bg-base-100 w-full max-w-sm shrink-0 shadow-2xl"> |
| 11 | + {#if step === "forgot"} |
| 12 | + <form |
| 13 | + class="card-body" |
| 14 | + onsubmit={(event) => { |
| 15 | + event.preventDefault(); |
| 16 | + const formData = new FormData(event.currentTarget); |
| 17 | + void signIn("password", formData).then( |
| 18 | + () => (step = { email: formData.get("email") as string }), |
| 19 | + ); |
| 20 | + }} |
| 21 | + > |
| 22 | + <h1 class="text-2xl font-bold">Reset Password</h1> |
| 23 | + <p class="text-base-content/70 text-sm"> |
| 24 | + Enter your email address and we will send you a code to reset your |
| 25 | + password. |
| 26 | + </p> |
| 27 | + <div class="form-control"> |
| 28 | + <label class="label" for="email"> |
| 29 | + <span class="label-text">Email</span> |
| 30 | + </label> |
| 31 | + <input |
| 32 | + id="email" |
| 33 | + name="email" |
| 34 | + placeholder="email" |
| 35 | + class="input input-bordered" |
| 36 | + required |
| 37 | + /> |
| 38 | + <input name="flow" type="hidden" value="reset" /> |
| 39 | + </div> |
| 40 | + <div class="form-control mt-6"> |
| 41 | + <button type="submit" class="btn btn-primary" disabled={isLoading}> |
| 42 | + {#if isLoading} |
| 43 | + <span class="loading loading-spinner"></span> |
| 44 | + {/if} |
| 45 | + Send Code |
| 46 | + </button> |
| 47 | + </div> |
| 48 | + </form> |
| 49 | + {:else} |
| 50 | + <form |
| 51 | + class="card-body" |
| 52 | + onsubmit={(event) => { |
| 53 | + event.preventDefault(); |
| 54 | + const formData = new FormData(event.currentTarget); |
| 55 | + void signIn("password", formData); |
| 56 | + }} |
| 57 | + > |
| 58 | + <h1 class="text-2xl font-bold">Enter Code</h1> |
| 59 | + <p class="text-base-content/70 text-sm"> |
| 60 | + A code has been sent to <strong>{step.email}</strong>. |
| 61 | + </p> |
| 62 | + <div class="form-control"> |
| 63 | + <label class="label" for="code"> |
| 64 | + <span class="label-text">Code</span> |
| 65 | + </label> |
| 66 | + <input |
| 67 | + id="code" |
| 68 | + name="code" |
| 69 | + placeholder="123456" |
| 70 | + class="input input-bordered" |
| 71 | + required |
| 72 | + /> |
| 73 | + </div> |
| 74 | + <div class="form-control"> |
| 75 | + <label class="label" for="newPassword"> |
| 76 | + <span class="label-text">New Password</span> |
| 77 | + </label> |
| 78 | + <input |
| 79 | + id="newPassword" |
| 80 | + name="newPassword" |
| 81 | + type="password" |
| 82 | + placeholder="new password" |
| 83 | + class="input input-bordered" |
| 84 | + required |
| 85 | + /> |
| 86 | + <input name="email" value={step.email} type="hidden" /> |
| 87 | + <input name="flow" value="reset-verification" type="hidden" /> |
| 88 | + </div> |
| 89 | + <div class="form-control mt-6"> |
| 90 | + <button type="submit" class="btn btn-primary" disabled={isLoading}> |
| 91 | + {#if isLoading} |
| 92 | + <span class="loading loading-spinner"></span> |
| 93 | + {/if} |
| 94 | + Continue |
| 95 | + </button> |
| 96 | + </div> |
| 97 | + <div class="mt-4 text-center"> |
| 98 | + <button |
| 99 | + type="button" |
| 100 | + class="link-hover link text-sm" |
| 101 | + onclick={() => (step = "forgot")} |
| 102 | + > |
| 103 | + Cancel |
| 104 | + </button> |
| 105 | + </div> |
| 106 | + </form> |
| 107 | + {/if} |
| 108 | + </div> |
| 109 | +</div> |
0 commit comments