Next.js Discord

Discord Forum

NextAuth conditional rendering

Unanswered
Pacific sand lance posted this in #help-forum
Open in Discord
Avatar
Pacific sand lanceOP
Hey, i was just trying to render a component based on the user's session

for example this is my code when i'm trying to show my admin component
"use client"

import AdminNav from "@/components/admincomponents/adminnavbar";
import Dashboard from "@/components/admincomponents/dashboard";
import { useSession } from "next-auth/react";
import { redirect } from "next/navigation";

export default function Admin() {
    
    const {data: session} = useSession()

    const boolAdmin = session?.user.isadmin

    if(boolAdmin == true) {
        return (
            <AdminNav adminname={session?.user.fullname} />
        )
    }
    return (
        redirect('/')
    )
}

But it showed only the homepage and not the admin, which means there's something wrong, when i try render if there is a session?.user, it works fine does anybody know how to fix this?

1 Reply

Avatar
Pacific sand lanceOP
hello??