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": {
|
||||
"title": "تسجيل الدخول إلى ميزي",
|
||||
"subtitle": "سيتم إرسال رمز التحقق إلى هاتفك",
|
||||
"redirecting": "مسجّل الدخول بالفعل — يتم التحويل…",
|
||||
"phone": "رقم الجوال",
|
||||
"phonePlaceholder": "٠٩١٢١٢٣٤٥٦٧",
|
||||
"sendOtp": "إرسال الرمز",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
"auth": {
|
||||
"title": "ورود به میزی",
|
||||
"subtitle": "کد تأیید به موبایل شما ارسال میشود",
|
||||
"redirecting": "قبلاً وارد شدهاید — در حال انتقال…",
|
||||
"phone": "شماره موبایل",
|
||||
"phonePlaceholder": "۰۹۱۲۱۲۳۴۵۶۷",
|
||||
"sendOtp": "ارسال کد",
|
||||
|
||||
@@ -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<LoginTab>("otp");
|
||||
|
||||
@@ -140,6 +149,14 @@ export default function LoginPage() {
|
||||
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 (
|
||||
<div className="flex min-h-screen items-center justify-center bg-muted/30 p-4">
|
||||
<Card className="w-full max-w-md">
|
||||
|
||||
Reference in New Issue
Block a user