|
| 1 | +--- |
| 2 | +import Layout from '../layouts/Layout.astro'; |
| 3 | +
|
| 4 | +const next = Astro.url.searchParams.get('next') || '/upload'; |
| 5 | +--- |
| 6 | + |
| 7 | +<Layout title="Staff Login - Tailspin Shelter"> |
| 8 | + <div class="py-8 max-w-md"> |
| 9 | + <h1 class="text-3xl font-bold text-slate-100 mb-3">Staff Login</h1> |
| 10 | + <p class="text-slate-300 mb-8">Sign in to upload and generate AI-assisted pet listings.</p> |
| 11 | + |
| 12 | + <form id="login-form" class="bg-slate-800/70 border border-slate-700 rounded-xl p-6 space-y-5" data-testid="login-form"> |
| 13 | + <input type="hidden" id="next-url" value={next} /> |
| 14 | + |
| 15 | + <div> |
| 16 | + <label for="email" class="block text-sm font-medium text-slate-200 mb-2">Email</label> |
| 17 | + <input |
| 18 | + id="email" |
| 19 | + name="email" |
| 20 | + type="email" |
| 21 | + autocomplete="username" |
| 22 | + required |
| 23 | + value="staff@tailspin.example" |
| 24 | + class="w-full rounded-lg border border-slate-600 bg-slate-900 px-3 py-2 text-slate-100 focus:border-blue-400 focus:outline-none" |
| 25 | + data-testid="login-email" |
| 26 | + /> |
| 27 | + </div> |
| 28 | + |
| 29 | + <div> |
| 30 | + <label for="password" class="block text-sm font-medium text-slate-200 mb-2">Password</label> |
| 31 | + <input |
| 32 | + id="password" |
| 33 | + name="password" |
| 34 | + type="password" |
| 35 | + autocomplete="current-password" |
| 36 | + required |
| 37 | + value="TailspinDemo123!" |
| 38 | + class="w-full rounded-lg border border-slate-600 bg-slate-900 px-3 py-2 text-slate-100 focus:border-blue-400 focus:outline-none" |
| 39 | + data-testid="login-password" |
| 40 | + /> |
| 41 | + </div> |
| 42 | + |
| 43 | + <p id="login-error" class="hidden text-sm text-red-400" data-testid="login-error"></p> |
| 44 | + |
| 45 | + <button |
| 46 | + type="submit" |
| 47 | + class="w-full rounded-lg bg-blue-600 px-4 py-2 font-medium text-white hover:bg-blue-700 transition-colors" |
| 48 | + data-testid="login-submit" |
| 49 | + > |
| 50 | + Sign in |
| 51 | + </button> |
| 52 | + </form> |
| 53 | + </div> |
| 54 | +</Layout> |
| 55 | + |
| 56 | +<script> |
| 57 | + const form = document.getElementById('login-form') as HTMLFormElement | null; |
| 58 | + const error = document.getElementById('login-error'); |
| 59 | + const nextUrl = (document.getElementById('next-url') as HTMLInputElement | null)?.value || '/upload'; |
| 60 | + |
| 61 | + form?.addEventListener('submit', async (event) => { |
| 62 | + event.preventDefault(); |
| 63 | + error?.classList.add('hidden'); |
| 64 | + |
| 65 | + const formData = new FormData(form); |
| 66 | + const response = await fetch('/api/auth/login', { |
| 67 | + method: 'POST', |
| 68 | + headers: { 'content-type': 'application/json' }, |
| 69 | + body: JSON.stringify({ |
| 70 | + email: formData.get('email'), |
| 71 | + password: formData.get('password'), |
| 72 | + }), |
| 73 | + }); |
| 74 | + |
| 75 | + if (response.ok) { |
| 76 | + window.location.href = nextUrl; |
| 77 | + return; |
| 78 | + } |
| 79 | + |
| 80 | + const data = await response.json().catch(() => ({ error: 'Unable to sign in' })); |
| 81 | + if (error) { |
| 82 | + error.textContent = data.error || 'Unable to sign in'; |
| 83 | + error.classList.remove('hidden'); |
| 84 | + } |
| 85 | + }); |
| 86 | +</script> |
0 commit comments