forked from BRETT/BRETT
Initial Commit
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<script setup lang="ts">
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
|
||||
const { register } = useAuth()
|
||||
const name = ref('')
|
||||
const password = ref('')
|
||||
const email = ref('')
|
||||
const errorMessage = ref('')
|
||||
const loading = ref(false)
|
||||
|
||||
async function onSubmit() {
|
||||
if (loading.value) return
|
||||
loading.value = true
|
||||
errorMessage.value = ''
|
||||
try {
|
||||
await register(name.value, password.value, email.value || undefined)
|
||||
await navigateTo('/')
|
||||
}
|
||||
catch (err) {
|
||||
const e = err as { data?: { statusMessage?: string, message?: string } }
|
||||
errorMessage.value = e.data?.statusMessage ?? e.data?.message ?? 'Registrierung fehlgeschlagen'
|
||||
}
|
||||
finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="mx-auto max-w-sm px-4 lg:px-6">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Registrieren</CardTitle>
|
||||
<CardDescription>Name und Passwort reichen — E-Mail ist optional.</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form class="space-y-4" @submit.prevent="onSubmit">
|
||||
<div class="space-y-1.5">
|
||||
<Label for="name">Name</Label>
|
||||
<Input id="name" v-model="name" autocomplete="username" required minlength="3" maxlength="50" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<Label for="password">Passwort</Label>
|
||||
<Input id="password" v-model="password" type="password" autocomplete="new-password" required minlength="6" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<Label for="email">E-Mail (optional)</Label>
|
||||
<Input id="email" v-model="email" type="email" autocomplete="email" />
|
||||
</div>
|
||||
<p v-if="errorMessage" class="text-sm text-destructive">
|
||||
{{ errorMessage }}
|
||||
</p>
|
||||
<Button type="submit" class="w-full" :disabled="loading">
|
||||
Konto erstellen
|
||||
</Button>
|
||||
<p class="text-center text-sm text-muted-foreground">
|
||||
Schon registriert?
|
||||
<NuxtLink to="/login" class="text-primary underline">
|
||||
Login
|
||||
</NuxtLink>
|
||||
</p>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user