Check pathname instead of session for account link visibility
- Replace useSession with usePathname from next/navigation - Show account link only when pathname includes '/home' (restricted pages) - More efficient than checking session state - Aligns with middleware logic that protects /home routes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -5,18 +5,19 @@ import Link from "next/link";
|
|||||||
import { SelectLanguage } from "./SelectLanguage";
|
import { SelectLanguage } from "./SelectLanguage";
|
||||||
import AccountCircle from "@mui/icons-material/AccountCircle";
|
import AccountCircle from "@mui/icons-material/AccountCircle";
|
||||||
import { useLocale } from "next-intl";
|
import { useLocale } from "next-intl";
|
||||||
import { useSession } from "next-auth/react";
|
import { usePathname } from "next/navigation";
|
||||||
|
|
||||||
export const PageHeader = () => {
|
export const PageHeader = () => {
|
||||||
const locale = useLocale();
|
const locale = useLocale();
|
||||||
const { data: session } = useSession();
|
const pathname = usePathname();
|
||||||
|
const isRestrictedPage = pathname.includes('/home');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="navbar bg-base-100 mb-6">
|
<div className="navbar bg-base-100 mb-6">
|
||||||
<Link className="btn btn-ghost text-xl" href={`/${locale}/home`}><Image src="/icon3.png" alt="logo" width={48} height={48} /> Režije</Link>
|
<Link className="btn btn-ghost text-xl" href={`/${locale}/home`}><Image src="/icon3.png" alt="logo" width={48} height={48} /> Režije</Link>
|
||||||
<span className="grow"> </span>
|
<span className="grow"> </span>
|
||||||
<SelectLanguage />
|
<SelectLanguage />
|
||||||
{session && (
|
{isRestrictedPage && (
|
||||||
<Link href={`/${locale}/home/account/`} className="btn btn-ghost btn-circle">
|
<Link href={`/${locale}/home/account/`} className="btn btn-ghost btn-circle">
|
||||||
<AccountCircle />
|
<AccountCircle />
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
Reference in New Issue
Block a user