From f584f581e50715762f7092ae3497826b5fc29296 Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Sat, 11 Jul 2026 15:12:58 +0330 Subject: [PATCH] fix(auth): correct login detection + return to origin after login MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - isUserLoggedIn() checked the access_token cookie, which is never set (access_token lives in memory / tokenStore; only userInfo + uuid are cookies). It therefore always returned false — the claim modal (and comment auth checks) kept showing the login prompt even when logged in. Now reads the userInfo cookie. - Claim modal login link carries ?redirect=; after OTP login SendReq returns to that path (guarded to internal "/..." only, blocks protocol-relative //) instead of always going to "/". Co-Authored-By: Claude Opus 4.8 (1M context) --- components/doctor/claim/index.js | 5 +++-- components/register/verificationPage/SendReq.js | 7 ++++++- helper/index.js | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/components/doctor/claim/index.js b/components/doctor/claim/index.js index b66ec22..f1badbe 100644 --- a/components/doctor/claim/index.js +++ b/components/doctor/claim/index.js @@ -1,7 +1,7 @@ "use client"; import { useState } from "react"; -import { useRouter } from "next/navigation"; +import { useRouter, usePathname } from "next/navigation"; import Link from "next/link"; import { Box, Button, Modal, TextField } from "@mui/material"; import { styleDefault } from "@/mui"; @@ -20,6 +20,7 @@ const initialForm = { national_code: "", birth_date: "", first_name: "", last_na */ function ClaimProfileSection({ doctor }) { const router = useRouter(); + const pathname = usePathname(); const [open, setOpen] = useState(false); const [form, setForm] = useState(initialForm); const [fieldErrors, setFieldErrors] = useState({}); @@ -179,7 +180,7 @@ function ClaimProfileSection({ doctor }) { برای احراز مالکیت، ابتدا با شماره موبایل خود وارد شوید. پس از ورود، به همین صفحه بازگردید و دوباره تلاش کنید.

- + diff --git a/components/register/verificationPage/SendReq.js b/components/register/verificationPage/SendReq.js index 8cd7585..94999b0 100644 --- a/components/register/verificationPage/SendReq.js +++ b/components/register/verificationPage/SendReq.js @@ -86,7 +86,12 @@ function SendReq({ if (setStep) { setStep(3); } else { - window.location.href = "/"; + // بازگشت به صفحهٔ مبدأ اگر ?redirect= داده شده (فقط مسیر داخلی امن) + const redirect = new URLSearchParams(window.location.search).get("redirect"); + window.location.href = + redirect && redirect.startsWith("/") && !redirect.startsWith("//") + ? redirect + : "/"; } } else { setIsError(true); diff --git a/helper/index.js b/helper/index.js index d8c1687..f6b6198 100644 --- a/helper/index.js +++ b/helper/index.js @@ -681,8 +681,8 @@ export function timeAgo(timestamp) { } export function isUserLoggedIn() { - const userInfo = Cookies.get("access_token"); - return !!userInfo; + // access_token در memory است نه کوکی؛ userInfo کوکیِ non-httpOnly است که هنگام لاگین ست می‌شود. + return !!Cookies.get("userInfo"); } export function convertTimestampToPersianDateSimple(timestamp) {