2026-05-18 20:18:28 +03:30
|
|
|
<template>
|
2026-05-23 18:13:25 +03:30
|
|
|
<AuthLayout title="منتایم" subtitle="ورود به حساب کاربری">
|
2026-05-18 20:18:28 +03:30
|
|
|
<p
|
|
|
|
|
v-if="error"
|
|
|
|
|
class="mb-4 rounded-xl border border-red-500/30 bg-red-500/10 px-4 py-3 text-sm text-red-600 dark:text-red-400"
|
|
|
|
|
>
|
|
|
|
|
{{ error }}
|
|
|
|
|
</p>
|
|
|
|
|
|
2026-05-23 13:14:52 +03:30
|
|
|
<AuthModeSwitch v-model="mode" />
|
|
|
|
|
|
2026-05-18 20:18:28 +03:30
|
|
|
<form class="mt-auto space-y-4" @submit.prevent="onSubmit">
|
|
|
|
|
<AppInput
|
|
|
|
|
id="mobile"
|
|
|
|
|
v-model="mobile"
|
|
|
|
|
label="شماره موبایل"
|
|
|
|
|
type="tel"
|
|
|
|
|
inputmode="numeric"
|
|
|
|
|
placeholder="09121234567"
|
|
|
|
|
autocomplete="tel"
|
|
|
|
|
ltr
|
|
|
|
|
required
|
|
|
|
|
/>
|
2026-05-23 13:14:52 +03:30
|
|
|
|
|
|
|
|
<AppInput
|
|
|
|
|
v-if="mode === 'password'"
|
|
|
|
|
id="password"
|
|
|
|
|
v-model="password"
|
|
|
|
|
label="رمز عبور"
|
|
|
|
|
type="password"
|
|
|
|
|
autocomplete="current-password"
|
|
|
|
|
ltr
|
|
|
|
|
required
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<AppButton type="submit" :loading="loading">
|
|
|
|
|
{{ mode === 'otp' ? 'دریافت کد تأیید' : 'ورود' }}
|
|
|
|
|
</AppButton>
|
2026-05-18 20:18:28 +03:30
|
|
|
</form>
|
2026-05-23 13:14:52 +03:30
|
|
|
|
|
|
|
|
<p v-if="mode === 'password'" class="mt-3 text-center text-xs text-muted">
|
|
|
|
|
اولین بار؟ با کد یکبارمصرف وارد شوید و در پروفایل رمز بسازید.
|
|
|
|
|
</p>
|
2026-05-18 20:18:28 +03:30
|
|
|
</AuthLayout>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2026-05-18 21:30:37 +03:30
|
|
|
import { ref } from 'vue';
|
|
|
|
|
import { useRouter } from 'vue-router';
|
2026-05-23 13:14:52 +03:30
|
|
|
import { loginWithPassword, requestOtp } from '@/api/auth';
|
|
|
|
|
import { isValidIranMobile, normalizeIranMobile } from '@/utils/mobile';
|
2026-05-18 20:18:28 +03:30
|
|
|
import { ApiError } from '@/api/client';
|
2026-05-23 13:14:52 +03:30
|
|
|
import AuthModeSwitch from '@/components/auth/AuthModeSwitch.vue';
|
|
|
|
|
import type { AuthLoginMode } from '@/components/auth/AuthModeSwitch.vue';
|
2026-05-18 20:18:28 +03:30
|
|
|
import AppButton from '@/components/ui/AppButton.vue';
|
|
|
|
|
import AppInput from '@/components/ui/AppInput.vue';
|
|
|
|
|
import AuthLayout from '@/layouts/AuthLayout.vue';
|
2026-05-23 13:14:52 +03:30
|
|
|
import { useAuthStore } from '@/stores/auth';
|
2026-05-18 20:18:28 +03:30
|
|
|
|
|
|
|
|
const router = useRouter();
|
2026-05-23 13:14:52 +03:30
|
|
|
const auth = useAuthStore();
|
|
|
|
|
const mode = ref<AuthLoginMode>('otp');
|
2026-05-18 20:18:28 +03:30
|
|
|
const mobile = ref('');
|
2026-05-23 13:14:52 +03:30
|
|
|
const password = ref('');
|
2026-05-18 20:18:28 +03:30
|
|
|
const loading = ref(false);
|
|
|
|
|
const error = ref('');
|
|
|
|
|
|
|
|
|
|
async function onSubmit() {
|
|
|
|
|
error.value = '';
|
|
|
|
|
loading.value = true;
|
|
|
|
|
try {
|
2026-05-23 13:14:52 +03:30
|
|
|
const normalized = normalizeIranMobile(mobile.value);
|
|
|
|
|
if (!isValidIranMobile(normalized)) {
|
|
|
|
|
error.value = 'شماره موبایل معتبر نیست. مثال: 09121234567';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mode.value === 'otp') {
|
|
|
|
|
const res = await requestOtp(normalized);
|
|
|
|
|
await router.push({
|
|
|
|
|
name: 'verify',
|
|
|
|
|
query: {
|
|
|
|
|
mobile: normalized,
|
|
|
|
|
expires: String(res.expiresInSeconds),
|
|
|
|
|
...(res.otpCode ? { devCode: res.otpCode } : {}),
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const res = await loginWithPassword(normalized, password.value);
|
|
|
|
|
auth.setSession(res.accessToken, res.user);
|
|
|
|
|
await router.replace({ name: 'app-home' });
|
2026-05-18 20:18:28 +03:30
|
|
|
} catch (e) {
|
|
|
|
|
error.value =
|
2026-05-23 13:14:52 +03:30
|
|
|
e instanceof ApiError ? e.message : 'خطا در ورود. دوباره تلاش کنید.';
|
2026-05-18 20:18:28 +03:30
|
|
|
} finally {
|
|
|
|
|
loading.value = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|