|
| 1 | +<template> |
| 2 | + <div> |
| 3 | + <div @click="focus = !focus"> |
| 4 | + <slot /> |
| 5 | + </div> |
| 6 | + <div |
| 7 | + v-if="focus" |
| 8 | + class="absolute -ml-52 mt-2 flex items-center justify-center"> |
| 9 | + <div class="rounded-lg bg-white p-6 shadow-lg"> |
| 10 | + <h2 class="mb-4 text-lg font-bold">Enter your shortcode email</h2> |
| 11 | + <input |
| 12 | + @keyup.enter="sendLoginEmail" |
| 13 | + :pattern="shortcodeEmailRegex.source" |
| 14 | + v-model="email" |
| 15 | + type="email" |
| 16 | + |
| 17 | + class="mb-4 w-full rounded border p-2 invalid:border-red-500" /> |
| 18 | + <div class="flex justify-end gap-2"> |
| 19 | + <button |
| 20 | + @click="focus = false" |
| 21 | + class="rounded bg-gray-300 px-4 py-2 hover:bg-gray-400"> |
| 22 | + Cancel |
| 23 | + </button> |
| 24 | + <button |
| 25 | + @click="sendLoginEmail" |
| 26 | + class="rounded bg-blue-500 px-4 py-2 text-white hover:bg-blue-600"> |
| 27 | + {{ loading ? 'Loading...' : 'Submit' }} |
| 28 | + </button> |
| 29 | + </div> |
| 30 | + </div> |
| 31 | + </div> |
| 32 | + </div> |
| 33 | +</template> |
| 34 | + |
| 35 | +<script lang="ts" setup> |
| 36 | +import { shortcodeEmailRegex } from '~~/hono/types'; |
| 37 | +
|
| 38 | +const focus = ref(false); |
| 39 | +const loading = ref(false); |
| 40 | +const email = ref(''); |
| 41 | +
|
| 42 | +const sendLoginEmail = async () => { |
| 43 | + if (loading.value) return; |
| 44 | + if (!shortcodeEmailRegex.test(email.value)) { |
| 45 | + return alert('Please use your Imperial shortcode email.'); |
| 46 | + } |
| 47 | +
|
| 48 | + loading.value = true; |
| 49 | + const res = await fetch('/api/auth/login', { |
| 50 | + method: 'POST', |
| 51 | + body: JSON.stringify({ email: email.value }), |
| 52 | + headers: { 'Content-Type': 'application/json' } |
| 53 | + }); |
| 54 | + loading.value = false; |
| 55 | +
|
| 56 | + if (res.ok) { |
| 57 | + alert('Login email sent! Please check your inbox.'); |
| 58 | + focus.value = false; |
| 59 | + email.value = ''; |
| 60 | + } else { |
| 61 | + alert('Failed to send login email. Please try again.'); |
| 62 | + } |
| 63 | +}; |
| 64 | +</script> |
0 commit comments