2026-10-28 16:57:43 +00:00
|
|
|
<script setup lang="ts">
|
2026-10-30 10:17:34 +00:00
|
|
|
import type { GameError } from '~/types/game'
|
|
|
|
|
|
2026-10-28 16:57:43 +00:00
|
|
|
const { register } = useAuth()
|
|
|
|
|
const errorText = useErrorText()
|
2026-10-30 10:17:34 +00:00
|
|
|
const { t } = useI18n()
|
2026-10-28 16:57:43 +00:00
|
|
|
const mock = isMockServer
|
|
|
|
|
|
2026-10-30 10:17:34 +00:00
|
|
|
const form = reactive({ name: '', email: '', password: '', again: '', terms: false })
|
|
|
|
|
/** The field the server (or the form) refused, and why. */
|
|
|
|
|
const problem = ref<{ field: string | null; text: string } | null>(null)
|
2026-10-28 16:57:43 +00:00
|
|
|
const busy = ref(false)
|
|
|
|
|
|
|
|
|
|
async function submit() {
|
2026-10-30 10:17:34 +00:00
|
|
|
if (form.password !== form.again) {
|
|
|
|
|
problem.value = { field: 'again', text: t('auth.password_mismatch') }
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-10-28 16:57:43 +00:00
|
|
|
busy.value = true
|
2026-10-30 10:17:34 +00:00
|
|
|
problem.value = null
|
2026-10-28 16:57:43 +00:00
|
|
|
try {
|
2026-10-30 10:17:34 +00:00
|
|
|
await register(form.name, form.email, form.password, form.terms)
|
2026-10-28 16:57:43 +00:00
|
|
|
await navigateTo('/worlds')
|
|
|
|
|
} catch (e) {
|
2026-10-30 10:17:34 +00:00
|
|
|
problem.value = { field: (e as GameError)?.field ?? null, text: errorText(e) }
|
2026-10-28 16:57:43 +00:00
|
|
|
} finally {
|
|
|
|
|
busy.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-10-30 10:17:34 +00:00
|
|
|
const wrong = (field: string) => problem.value?.field === field
|
2026-10-28 16:57:43 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
2026-10-30 10:17:34 +00:00
|
|
|
<div>
|
|
|
|
|
<UiAuthCard :title="$t('auth.register.title')">
|
|
|
|
|
<p v-if="mock" class="mb-4 border border-gold-600 bg-parchment-200 px-3 py-2 text-xs text-wood-900">{{ $t('auth.mock_hint') }}</p>
|
|
|
|
|
<form class="space-y-4" novalidate @submit.prevent="submit">
|
|
|
|
|
<label class="block">
|
|
|
|
|
<span class="label">{{ $t('auth.name') }}</span>
|
|
|
|
|
<input v-model="form.name" class="input" :class="wrong('name') ? 'border-blood-700' : ''" type="text" autocomplete="nickname" maxlength="24" required :aria-invalid="wrong('name')" />
|
|
|
|
|
<span class="mt-1 block text-xs" :class="wrong('name') ? 'font-semibold text-blood-700' : 'text-ink-500'">{{ wrong('name') ? problem!.text : $t('auth.name_hint') }}</span>
|
|
|
|
|
</label>
|
|
|
|
|
<label class="block">
|
|
|
|
|
<span class="label">{{ $t('auth.email') }}</span>
|
|
|
|
|
<input v-model="form.email" class="input" :class="wrong('email') ? 'border-blood-700' : ''" type="email" autocomplete="email" required :aria-invalid="wrong('email')" />
|
|
|
|
|
<span v-if="wrong('email')" class="mt-1 block text-xs font-semibold text-blood-700">{{ problem!.text }}</span>
|
|
|
|
|
</label>
|
|
|
|
|
<label class="block">
|
|
|
|
|
<span class="label">{{ $t('auth.password') }}</span>
|
|
|
|
|
<input v-model="form.password" class="input" :class="wrong('password') ? 'border-blood-700' : ''" type="password" autocomplete="new-password" required :aria-invalid="wrong('password')" />
|
|
|
|
|
<span class="mt-1 block text-xs" :class="wrong('password') ? 'font-semibold text-blood-700' : 'text-ink-500'">{{ wrong('password') ? problem!.text : $t('auth.password_hint') }}</span>
|
|
|
|
|
</label>
|
|
|
|
|
<label class="block">
|
|
|
|
|
<span class="label">{{ $t('auth.password_again') }}</span>
|
|
|
|
|
<input v-model="form.again" class="input" :class="wrong('again') ? 'border-blood-700' : ''" type="password" autocomplete="new-password" required :aria-invalid="wrong('again')" />
|
|
|
|
|
<span v-if="wrong('again')" class="mt-1 block text-xs font-semibold text-blood-700">{{ problem!.text }}</span>
|
|
|
|
|
</label>
|
|
|
|
|
<label class="flex items-start gap-2 text-sm">
|
|
|
|
|
<input v-model="form.terms" type="checkbox" class="mt-1" :aria-invalid="wrong('terms')" />
|
|
|
|
|
<i18n-t keypath="auth.terms" tag="span" :class="wrong('terms') ? 'font-semibold text-blood-700' : ''">
|
|
|
|
|
<template #terms><NuxtLink to="/terms" target="_blank" class="font-semibold text-blood-700 underline">{{ $t('auth.terms_link') }}</NuxtLink></template>
|
|
|
|
|
<template #privacy><NuxtLink to="/privacy" target="_blank" class="font-semibold text-blood-700 underline">{{ $t('auth.privacy_link') }}</NuxtLink></template>
|
|
|
|
|
</i18n-t>
|
|
|
|
|
</label>
|
|
|
|
|
<p v-if="problem && !problem.field" class="alert" role="alert">{{ problem.text }}</p>
|
|
|
|
|
<p v-else-if="problem?.field === 'terms'" class="alert" role="alert">{{ problem.text }}</p>
|
|
|
|
|
<button type="submit" class="btn btn-primary w-full py-2" :disabled="busy">{{ $t('auth.register.submit') }}</button>
|
|
|
|
|
</form>
|
|
|
|
|
<template #footer>
|
|
|
|
|
<NuxtLink to="/login" class="font-semibold text-blood-700 hover:underline">{{ $t('auth.register.to_login') }}</NuxtLink>
|
|
|
|
|
</template>
|
|
|
|
|
</UiAuthCard>
|
|
|
|
|
<GameFooter />
|
|
|
|
|
</div>
|
2026-10-28 16:57:43 +00:00
|
|
|
</template>
|