game-village-politics-frontend/app/pages/login.vue

42 lines
1.2 KiB
Vue

<script setup lang="ts">
const { login } = useAuth()
const errorText = useErrorText()
const mock = isMockServer
const email = ref('')
const password = ref('')
const error = ref<string | null>(null)
const busy = ref(false)
async function submit() {
busy.value = true
error.value = null
try {
await login(email.value, password.value)
await navigateTo('/worlds')
} catch (e) {
error.value = errorText(e)
} finally {
busy.value = false
}
}
</script>
<template>
<section>
<h1>{{ $t('auth.login.title') }}</h1>
<p v-if="mock"><small>{{ $t('auth.mock_hint') }}</small></p>
<form @submit.prevent="submit">
<p>
<label>{{ $t('auth.email') }}<br /><input v-model="email" type="email" autocomplete="email" required /></label>
</p>
<p>
<label>{{ $t('auth.password') }}<br /><input v-model="password" type="password" autocomplete="current-password" required /></label>
</p>
<p v-if="error" role="alert">{{ error }}</p>
<button type="submit" :disabled="busy">{{ $t('auth.login.submit') }}</button>
</form>
<p><NuxtLink to="/register">{{ $t('auth.login.to_register') }}</NuxtLink></p>
</section>
</template>