diff --git a/web/dashboard/messages/ar.json b/web/dashboard/messages/ar.json index 221dae1..59147fb 100644 --- a/web/dashboard/messages/ar.json +++ b/web/dashboard/messages/ar.json @@ -39,6 +39,7 @@ "auth": { "title": "تسجيل الدخول إلى ميزي", "subtitle": "سيتم إرسال رمز التحقق إلى هاتفك", + "redirecting": "مسجّل الدخول بالفعل — يتم التحويل…", "phone": "رقم الجوال", "phonePlaceholder": "٠٩١٢١٢٣٤٥٦٧", "sendOtp": "إرسال الرمز", diff --git a/web/dashboard/messages/en.json b/web/dashboard/messages/en.json index 301c1f5..26ade1a 100644 --- a/web/dashboard/messages/en.json +++ b/web/dashboard/messages/en.json @@ -39,6 +39,7 @@ "auth": { "title": "Sign in to Meezi", "subtitle": "We will send a verification code to your phone", + "redirecting": "Already signed in — redirecting…", "phone": "Mobile number", "phonePlaceholder": "09121234567", "sendOtp": "Send code", diff --git a/web/dashboard/messages/fa.json b/web/dashboard/messages/fa.json index 118d563..36f0fe1 100644 --- a/web/dashboard/messages/fa.json +++ b/web/dashboard/messages/fa.json @@ -39,6 +39,7 @@ "auth": { "title": "ورود به میزی", "subtitle": "کد تأیید به موبایل شما ارسال می‌شود", + "redirecting": "قبلاً وارد شده‌اید — در حال انتقال…", "phone": "شماره موبایل", "phonePlaceholder": "۰۹۱۲۱۲۳۴۵۶۷", "sendOtp": "ارسال کد", diff --git a/web/dashboard/src/app/[locale]/login/page.tsx b/web/dashboard/src/app/[locale]/login/page.tsx index 7bb8759..91abf83 100644 --- a/web/dashboard/src/app/[locale]/login/page.tsx +++ b/web/dashboard/src/app/[locale]/login/page.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState } from "react"; +import { useState, useEffect } from "react"; import { useTranslations } from "next-intl"; import { useRouter, Link } from "@/i18n/routing"; import { apiPost, ApiClientError } from "@/lib/api/client"; @@ -18,6 +18,15 @@ export default function LoginPage() { const t = useTranslations("auth"); const router = useRouter(); const setAuth = useAuthStore((s) => s.setAuth); + const user = useAuthStore((s) => s.user); + const hasHydrated = useAuthStore((s) => s._hasHydrated); + + // Already signed in? Don't show the login form again — send them to the app. + // Gate on _hasHydrated so we don't act on a not-yet-rehydrated (null) session. + const alreadyAuthed = hasHydrated && !!user?.accessToken; + useEffect(() => { + if (alreadyAuthed) router.replace("/pos"); + }, [alreadyAuthed, router]); const [tab, setTab] = useState("otp"); @@ -140,6 +149,14 @@ export default function LoginPage() { setCode(""); }; + if (alreadyAuthed) { + return ( +
+

{t("redirecting")}

+
+ ); + } + return (