fix(auth): redirect already-signed-in users away from the login page
CI/CD / CI · API (dotnet build + test) (push) Successful in 40s
CI/CD / CI · Admin API (dotnet build) (push) Successful in 30s
CI/CD / CI · Dashboard (tsc) (push) Successful in 1m10s
CI/CD / CI · Admin Web (tsc) (push) Successful in 38s
CI/CD / CI · Website (tsc) (push) Successful in 47s
CI/CD / CI · Koja (tsc) (push) Successful in 49s
CI/CD / Deploy · all services (push) Successful in 2m57s
CI/CD / CI · API (dotnet build + test) (push) Successful in 40s
CI/CD / CI · Admin API (dotnet build) (push) Successful in 30s
CI/CD / CI · Dashboard (tsc) (push) Successful in 1m10s
CI/CD / CI · Admin Web (tsc) (push) Successful in 38s
CI/CD / CI · Website (tsc) (push) Successful in 47s
CI/CD / CI · Koja (tsc) (push) Successful in 49s
CI/CD / Deploy · all services (push) Successful in 2m57s
Visiting /login while authenticated now redirects to the app (/pos) instead of showing the login form again. Guarded on _hasHydrated so the not-yet-rehydrated (null) session isn't misread, and renders a brief "redirecting" state instead of flashing the form. fa/en/ar strings added. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -39,6 +39,7 @@
|
|||||||
"auth": {
|
"auth": {
|
||||||
"title": "تسجيل الدخول إلى ميزي",
|
"title": "تسجيل الدخول إلى ميزي",
|
||||||
"subtitle": "سيتم إرسال رمز التحقق إلى هاتفك",
|
"subtitle": "سيتم إرسال رمز التحقق إلى هاتفك",
|
||||||
|
"redirecting": "مسجّل الدخول بالفعل — يتم التحويل…",
|
||||||
"phone": "رقم الجوال",
|
"phone": "رقم الجوال",
|
||||||
"phonePlaceholder": "٠٩١٢١٢٣٤٥٦٧",
|
"phonePlaceholder": "٠٩١٢١٢٣٤٥٦٧",
|
||||||
"sendOtp": "إرسال الرمز",
|
"sendOtp": "إرسال الرمز",
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
"auth": {
|
"auth": {
|
||||||
"title": "Sign in to Meezi",
|
"title": "Sign in to Meezi",
|
||||||
"subtitle": "We will send a verification code to your phone",
|
"subtitle": "We will send a verification code to your phone",
|
||||||
|
"redirecting": "Already signed in — redirecting…",
|
||||||
"phone": "Mobile number",
|
"phone": "Mobile number",
|
||||||
"phonePlaceholder": "09121234567",
|
"phonePlaceholder": "09121234567",
|
||||||
"sendOtp": "Send code",
|
"sendOtp": "Send code",
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
"auth": {
|
"auth": {
|
||||||
"title": "ورود به میزی",
|
"title": "ورود به میزی",
|
||||||
"subtitle": "کد تأیید به موبایل شما ارسال میشود",
|
"subtitle": "کد تأیید به موبایل شما ارسال میشود",
|
||||||
|
"redirecting": "قبلاً وارد شدهاید — در حال انتقال…",
|
||||||
"phone": "شماره موبایل",
|
"phone": "شماره موبایل",
|
||||||
"phonePlaceholder": "۰۹۱۲۱۲۳۴۵۶۷",
|
"phonePlaceholder": "۰۹۱۲۱۲۳۴۵۶۷",
|
||||||
"sendOtp": "ارسال کد",
|
"sendOtp": "ارسال کد",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import { useRouter, Link } from "@/i18n/routing";
|
import { useRouter, Link } from "@/i18n/routing";
|
||||||
import { apiPost, ApiClientError } from "@/lib/api/client";
|
import { apiPost, ApiClientError } from "@/lib/api/client";
|
||||||
@@ -18,6 +18,15 @@ export default function LoginPage() {
|
|||||||
const t = useTranslations("auth");
|
const t = useTranslations("auth");
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const setAuth = useAuthStore((s) => s.setAuth);
|
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<LoginTab>("otp");
|
const [tab, setTab] = useState<LoginTab>("otp");
|
||||||
|
|
||||||
@@ -140,6 +149,14 @@ export default function LoginPage() {
|
|||||||
setCode("");
|
setCode("");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (alreadyAuthed) {
|
||||||
|
return (
|
||||||
|
<div className="flex min-h-screen items-center justify-center bg-muted/30 p-4">
|
||||||
|
<p className="text-sm text-muted-foreground">{t("redirecting")}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex min-h-screen items-center justify-center bg-muted/30 p-4">
|
<div className="flex min-h-screen items-center justify-center bg-muted/30 p-4">
|
||||||
<Card className="w-full max-w-md">
|
<Card className="w-full max-w-md">
|
||||||
|
|||||||
Reference in New Issue
Block a user