- Updated frontend-nuxt.mdc to specify usage of composables for API calls. - Added new AuthCard and ConfirmModal components for improved UI consistency. - Introduced UserAvatar component for user profile display, replacing previous Gravatar implementation. - Implemented useFormSubmit composable for handling form submissions with loading and error states. - Enhanced vitest.config.ts to include coverage reporting for composables and components. - Removed deprecated useAdminApi and useAuth composables to streamline API interactions. - Updated login and setup pages to utilize new components and composables for better user experience.
54 lines
1.9 KiB
Vue
54 lines
1.9 KiB
Vue
<template>
|
|
<div class="min-h-screen flex flex-col items-center justify-center bg-gradient-to-br from-base-200 via-base-300 to-primary/10 p-4 overflow-hidden">
|
|
<AuthCard>
|
|
<h1 class="card-title justify-center">First-time setup</h1>
|
|
<p class="text-sm text-base-content/80">
|
|
This is the first run. Create the administrator account using the bootstrap password
|
|
from the server configuration (e.g. <code class="text-xs">HNHMAP_BOOTSTRAP_PASSWORD</code>).
|
|
</p>
|
|
<form @submit.prevent="submit" class="flex flex-col gap-4">
|
|
<PasswordInput
|
|
v-model="pass"
|
|
label="Bootstrap password"
|
|
required
|
|
autocomplete="current-password"
|
|
/>
|
|
<p v-if="error" class="text-error text-sm">{{ error }}</p>
|
|
<button type="submit" class="btn btn-primary min-h-11 touch-manipulation" :disabled="loading">
|
|
<span v-if="loading" class="loading loading-spinner loading-sm" />
|
|
<span v-else>Create and log in</span>
|
|
</button>
|
|
</form>
|
|
</AuthCard>
|
|
<NuxtLink to="/" class="link link-hover underline underline-offset-2 mt-4 text-primary">Map</NuxtLink>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
// No auth required; auth.global skips this path
|
|
|
|
const pass = ref('')
|
|
const router = useRouter()
|
|
const api = useMapApi()
|
|
const { loading, error, run } = useFormSubmit('Setup failed')
|
|
|
|
onMounted(async () => {
|
|
try {
|
|
const { setupRequired: required } = await api.setupRequired()
|
|
if (!required) await navigateTo('/login')
|
|
} catch {
|
|
// If API fails, stay on page
|
|
}
|
|
})
|
|
|
|
async function submit() {
|
|
const ok = await run(async () => {
|
|
await api.login('admin', pass.value)
|
|
await router.push('/profile')
|
|
})
|
|
if (!ok && error.value === 'Unauthorized') {
|
|
error.value = 'Invalid bootstrap password.'
|
|
}
|
|
}
|
|
</script>
|