Spaces:
Paused
Paused
File size: 2,523 Bytes
a38005e c5ec7be a38005e 5afb157 a38005e edf424c a38005e ed3fb12 a38005e c5ec7be a38005e c5ec7be a38005e c5ec7be a38005e edf424c a38005e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | <script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
const auth = useAuthStore()
const router = useRouter()
const username = ref('')
const password = ref('')
const confirmPassword = ref('')
const error = ref('')
const loading = ref(false)
async function handleSetup() {
error.value = ''
if (password.value !== confirmPassword.value) {
error.value = 'Passwords do not match'
return
}
if (password.value.length < 8) {
error.value = 'Password must be at least 8 characters'
return
}
loading.value = true
try {
const ok = await auth.setup(username.value, password.value)
if (ok) {
router.push('/admin')
} else {
error.value = 'Setup failed. An admin account may already exist.'
}
} catch {
error.value = 'Setup failed'
} finally {
loading.value = false
}
}
</script>
<template>
<main class="min-h-screen flex items-center justify-center">
<div class="w-full max-w-sm space-y-6">
<div class="text-center">
<h1 class="text-2xl font-normal">OpenPosterDB Setup</h1>
<p class="text-muted-foreground">Create your admin account</p>
</div>
<form class="space-y-4" @submit.prevent="handleSetup">
<div>
<Label for="username" class="mb-1">Username</Label>
<Input
id="username"
v-model="username"
type="text"
autocomplete="username"
required
/>
</div>
<div>
<Label for="password" class="mb-1">Password</Label>
<Input
id="password"
v-model="password"
type="password"
autocomplete="new-password"
required
/>
</div>
<div>
<Label for="confirm-password" class="mb-1">Confirm Password</Label>
<Input
id="confirm-password"
v-model="confirmPassword"
type="password"
autocomplete="new-password"
required
/>
</div>
<p v-if="error" class="text-sm text-destructive">{{ error }}</p>
<Button type="submit" class="w-full" :disabled="loading">
{{ loading ? 'Creating account...' : 'Create admin account' }}
</Button>
</form>
</div>
</main>
</template>
|