fix(header): detect login state live from client cookie

The header decided between profile and login button only from the
server-passed logged prop (read once via cookies() in StLayout), so a
user who logged in client-side still saw ورود | ثبت نام until a hard
reload. Seed isLogged from the server prop (correct first paint, no
hydration mismatch) then sync it from the access_token cookie on mount
and on every route change, so login/logout reflect immediately.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
hamed
2026-06-15 18:41:58 +03:30
co-authored by Claude Opus 4.8
parent d114730768
commit 83b2ec21b7
2 changed files with 123 additions and 2 deletions
+10 -2
View File
@@ -7,11 +7,19 @@ import Row from "./list/Row";
import Col from "./list/col";
import ButtonMenu from "./list/col/ButtonMenu";
import BgGray from "./list/col/BgGray";
import { useState } from "react";
import { useEffect, useState } from "react";
import { usePathname } from "next/navigation";
import Cookies from "js-cookie";
import ProfileUser from "./profile";
function Content({ matchedCity, name, logged }) {
const [isActive, setIsActive] = useState(false);
const [isLogged, setIsLogged] = useState(Boolean(logged));
const pathname = usePathname();
useEffect(() => {
setIsLogged(Boolean(Cookies.get("access_token")));
}, [pathname]);
return (
<div
@@ -33,7 +41,7 @@ function Content({ matchedCity, name, logged }) {
</div>
</div>
<Row name={name} />
{logged ? (
{isLogged ? (
<ProfileUser />
) : (
<Link href="/login">