48 lines
1.5 KiB
Vue
48 lines
1.5 KiB
Vue
<script setup lang="ts">
|
|
const { $api } = useNuxtApp();
|
|
const session = useSessionStore();
|
|
const { t: translate } = useI18n();
|
|
const email = ref("");
|
|
const password = ref("");
|
|
const error = ref("");
|
|
const busy = ref(false);
|
|
|
|
async function submit(): Promise<void> {
|
|
error.value = "";
|
|
busy.value = true;
|
|
try {
|
|
const auth = await $api.login(email.value.trim(), password.value);
|
|
if (auth.user.role !== "shop_owner" && auth.user.role !== "shop_staff") {
|
|
error.value = translate("auth.shopRoleError");
|
|
return;
|
|
}
|
|
session.setAuth(auth);
|
|
await navigateTo("/");
|
|
} catch (err: unknown) {
|
|
error.value = err instanceof Error ? err.message : translate("common.error");
|
|
} finally {
|
|
busy.value = false;
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<main class="page">
|
|
<form class="card form-narrow" @submit.prevent="submit">
|
|
<h1 class="page-title">{{ $t("auth.welcome") }}</h1>
|
|
<div v-if="error" class="error-text" role="alert">{{ error }}</div>
|
|
<div class="field">
|
|
<label for="email">{{ $t("common.email") }}</label>
|
|
<input id="email" v-model="email" type="email" autocomplete="username" required />
|
|
</div>
|
|
<div class="field">
|
|
<label for="password">{{ $t("common.password") }}</label>
|
|
<input id="password" v-model="password" type="password" autocomplete="current-password" required />
|
|
</div>
|
|
<button class="btn primary" type="submit" :disabled="busy">
|
|
{{ busy ? $t("common.loading") : $t("common.login") }}
|
|
</button>
|
|
</form>
|
|
</main>
|
|
</template>
|