85 lines
2.1 KiB
Vue
85 lines
2.1 KiB
Vue
<script setup lang="ts">
|
|
import { ref } from 'vue'
|
|
import type { User } from '~/types'
|
|
import { apiErrorMessage } from '~/utils/errors'
|
|
|
|
definePageMeta({ layout: 'auth' })
|
|
useHead({ title: 'Sign in · Rhema Together' })
|
|
|
|
const api = useApi()
|
|
const { session, load } = useSession()
|
|
|
|
const identifier = ref('')
|
|
const password = ref('')
|
|
const submitting = ref(false)
|
|
const error = ref('')
|
|
|
|
async function submit() {
|
|
if (submitting.value) return
|
|
submitting.value = true
|
|
error.value = ''
|
|
try {
|
|
await api.post<User>('/login', {
|
|
identifier: identifier.value.trim(),
|
|
password: password.value,
|
|
})
|
|
await load(true)
|
|
await navigateTo('/rooms', { replace: true })
|
|
} catch (err) {
|
|
error.value = apiErrorMessage(err)
|
|
} finally {
|
|
submitting.value = false
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div>
|
|
<h1 class="auth-title">Sign in</h1>
|
|
<p class="auth-note">Use your handle or email.</p>
|
|
|
|
<form class="form" @submit.prevent="submit">
|
|
<div class="field">
|
|
<label class="field-label" for="login-identifier">Handle or email</label>
|
|
<input
|
|
id="login-identifier"
|
|
v-model="identifier"
|
|
class="input"
|
|
type="text"
|
|
autocomplete="username"
|
|
spellcheck="false"
|
|
autofocus
|
|
required
|
|
>
|
|
</div>
|
|
|
|
<div class="field">
|
|
<label class="field-label" for="login-password">Password</label>
|
|
<input
|
|
id="login-password"
|
|
v-model="password"
|
|
class="input"
|
|
type="password"
|
|
autocomplete="current-password"
|
|
required
|
|
>
|
|
</div>
|
|
|
|
<p v-if="error" class="form-error" role="alert">{{ error }}</p>
|
|
|
|
<button type="submit" class="btn btn-primary" :disabled="submitting">
|
|
{{ submitting ? 'Signing in' : 'Sign in' }}
|
|
</button>
|
|
</form>
|
|
|
|
<div class="auth-footer">
|
|
<template v-if="session.allowRegistration">
|
|
No account yet? <NuxtLink to="/register">Register</NuxtLink>
|
|
</template>
|
|
<template v-else>
|
|
Registration is closed. Ask a room owner for an invite link.
|
|
</template>
|
|
</div>
|
|
</div>
|
|
</template>
|