|
1 | 1 | <script setup lang="ts"> |
2 | 2 | const { user } = useAtproto() |
| 3 | +
|
| 4 | +const isResetting = ref(false) |
| 5 | +const resetEmail = ref('') |
| 6 | +const isCodeSent = ref(false) |
| 7 | +const resetToken = ref('') |
| 8 | +const newPassword = ref('') |
| 9 | +const isConfirming = ref(false) |
| 10 | +
|
| 11 | +const errorMessage = ref('') |
| 12 | +const successMessage = ref('') |
| 13 | +
|
| 14 | +async function handlePasswordReset() { |
| 15 | + errorMessage.value = '' |
| 16 | + successMessage.value = '' |
| 17 | +
|
| 18 | + if (!resetEmail.value) { |
| 19 | + errorMessage.value = 'Please enter your email first.' |
| 20 | + return |
| 21 | + } |
| 22 | +
|
| 23 | + isResetting.value = true |
| 24 | + try { |
| 25 | + await $fetch('/api/atproto/password-reset', { |
| 26 | + method: 'POST', |
| 27 | + body: { email: resetEmail.value }, |
| 28 | + }) |
| 29 | +
|
| 30 | + isCodeSent.value = true |
| 31 | + successMessage.value = 'Code sent! Check your email.' |
| 32 | + } catch (e: any) { |
| 33 | + errorMessage.value = e.statusMessage || 'Something went wrong. Please try again.' |
| 34 | + } finally { |
| 35 | + isResetting.value = false |
| 36 | + } |
| 37 | +} |
| 38 | +
|
| 39 | +async function handleConfirmReset() { |
| 40 | + errorMessage.value = '' |
| 41 | + successMessage.value = '' |
| 42 | +
|
| 43 | + if (!resetToken.value || !newPassword.value) { |
| 44 | + errorMessage.value = 'Please enter both the code and your new password.' |
| 45 | + return |
| 46 | + } |
| 47 | +
|
| 48 | + isConfirming.value = true |
| 49 | + try { |
| 50 | + await $fetch('/api/atproto/password-reset-confirm', { |
| 51 | + method: 'POST', |
| 52 | + body: { |
| 53 | + token: resetToken.value, |
| 54 | + password: newPassword.value, |
| 55 | + }, |
| 56 | + }) |
| 57 | +
|
| 58 | + successMessage.value = 'Password updated successfully!' |
| 59 | +
|
| 60 | + // Reset the form |
| 61 | + isCodeSent.value = false |
| 62 | + resetToken.value = '' |
| 63 | + newPassword.value = '' |
| 64 | + resetEmail.value = '' |
| 65 | + } catch (e: any) { |
| 66 | + errorMessage.value = e.statusMessage || 'Failed to update password. Check your code.' |
| 67 | + } finally { |
| 68 | + isConfirming.value = false |
| 69 | + } |
| 70 | +} |
3 | 71 | </script> |
4 | 72 |
|
5 | 73 | <template> |
@@ -42,23 +110,63 @@ const { user } = useAtproto() |
42 | 110 | > |
43 | 111 | <div> |
44 | 112 | <h2 class="font-mono text-xl mb-1">Email Address</h2> |
45 | | - <p class="text-sm text-fg-muted">Update the email address used for account recovery.</p> |
| 113 | + <p class="text-sm text-fg-muted">Update the email address of your account.</p> |
46 | 114 | </div> |
47 | 115 | <ButtonBase variant="secondary">Request Email Change</ButtonBase> |
48 | 116 | </section> |
49 | 117 |
|
50 | 118 | <section |
51 | | - class="p-6 bg-bg-subtle border border-border rounded-lg flex flex-col sm:flex-row sm:items-center justify-between gap-4" |
| 119 | + class="flex flex-col gap-2 max-w-sm p-4 border border-border rounded-lg bg-bg-subtle" |
52 | 120 | > |
53 | | - <div> |
54 | | - <h2 class="font-mono text-xl mb-1">Password Reset</h2> |
55 | | - <p class="text-sm text-fg-muted"> |
56 | | - Send a secure password reset link to your registered email. |
| 121 | + <h3 class="font-mono text-lg text-fg">Reset Password</h3> |
| 122 | + |
| 123 | + <p v-if="errorMessage" class="text-sm text-red-500 mb-2">{{ errorMessage }}</p> |
| 124 | + <p v-if="successMessage" class="text-sm text-green-500 mb-2">{{ successMessage }}</p> |
| 125 | + |
| 126 | + <div v-if="!isCodeSent"> |
| 127 | + <p class="text-sm text-fg-muted mb-2"> |
| 128 | + Enter your atmosphere email to receive a reset link. |
57 | 129 | </p> |
| 130 | + <input |
| 131 | + v-model="resetEmail" |
| 132 | + type="email" |
| 133 | + placeholder="you@example.com" |
| 134 | + class="w-full bg-bg border border-border rounded-md px-3 py-2 text-sm text-fg focus:border-accent outline-none mb-2" |
| 135 | + /> |
| 136 | + <ButtonBase |
| 137 | + variant="secondary" |
| 138 | + class="text-red-500 mt-2" |
| 139 | + :disabled="isResetting || !resetEmail" |
| 140 | + @click="handlePasswordReset" |
| 141 | + > |
| 142 | + {{ isResetting ? 'Sending...' : 'Send Reset Code' }} |
| 143 | + </ButtonBase> |
| 144 | + </div> |
| 145 | + |
| 146 | + <div v-else class="flex flex-col gap-2"> |
| 147 | + <input |
| 148 | + v-model="resetToken" |
| 149 | + type="text" |
| 150 | + placeholder="Reset Code (e.g. ABC-DEF)" |
| 151 | + class="w-full bg-bg border border-border rounded-md px-3 py-2 text-sm text-fg focus:border-accent outline-none" |
| 152 | + /> |
| 153 | + |
| 154 | + <input |
| 155 | + v-model="newPassword" |
| 156 | + type="password" |
| 157 | + placeholder="New Password" |
| 158 | + class="w-full bg-bg border border-border rounded-md px-3 py-2 text-sm text-fg focus:border-accent outline-none" |
| 159 | + /> |
| 160 | + |
| 161 | + <ButtonBase |
| 162 | + variant="secondary" |
| 163 | + class="text-red-500 mt-2" |
| 164 | + :disabled="isConfirming || !resetToken || !newPassword" |
| 165 | + @click="handleConfirmReset" |
| 166 | + > |
| 167 | + {{ isConfirming ? 'Saving...' : 'Save New Password' }} |
| 168 | + </ButtonBase> |
58 | 169 | </div> |
59 | | - <ButtonBase variant="secondary" class="text-red-500 hover:bg-red-500/10 border-red-500/20"> |
60 | | - Reset Password |
61 | | - </ButtonBase> |
62 | 170 | </section> |
63 | 171 | </div> |
64 | 172 | </main> |
|
0 commit comments