Skip to content

Commit 1514587

Browse files
fix(navbar): update TopNav component to use isLoggedIn for rendering links
1 parent b9474bb commit 1514587

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/app/actions/userActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,6 @@ export async function getUserInfoForNav() {
117117
})
118118
} catch (error) {
119119
console.log(error);
120-
throw error;
120+
return null;
121121
}
122122
}

src/app/layout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default async function RootLayout({
2121
}>) {
2222
const session = await auth();
2323
const userId = session?.user?.id || null;
24+
const isLoggedIn = Boolean(userId);
2425

2526
// Don't rely on session.user.image here: with JWT sessions it won't change
2627
// until the token is refreshed (often only on re-login).
@@ -33,7 +34,7 @@ export default async function RootLayout({
3334
<html lang="en">
3435
<body>
3536
<Providers profileComplete={profileComplete} userId={userId}>
36-
<TopNav userInfo={userInfo} isAdmin={isAdmin} />
37+
<TopNav userInfo={userInfo} isLoggedIn={isLoggedIn} isAdmin={isAdmin} />
3738
<main className="container mx-auto">
3839
{children}
3940
</main>

src/components/navbar/TopNav.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ type Props = {
1818
name: string | null;
1919
image: string | null;
2020
} | null;
21+
isLoggedIn: boolean;
2122
isAdmin: boolean;
2223
};
2324

2425
export default function TopNav({
2526
userInfo,
27+
isLoggedIn,
2628
isAdmin,
2729
}: Props) {
2830

@@ -71,7 +73,7 @@ export default function TopNav({
7173
</div>
7274
</NavbarBrand>
7375
<NavbarContent justify="center">
74-
{userInfo &&
76+
{isLoggedIn &&
7577
links.map((item) => (
7678
<NavLink
7779
key={item.href}
@@ -84,7 +86,7 @@ export default function TopNav({
8486
justify="end"
8587
className="flex-1"
8688
>
87-
{userInfo ? (
89+
{isLoggedIn ? (
8890
<div className="ml-auto">
8991
<UserMenu userInfo={userInfo} />
9092
</div>

0 commit comments

Comments
 (0)