'server-only' cannot be imported from a Client Component module. It should only be used from a Server Component. #77370
-
SummaryRepository: https://github.com/abdulazizkhatamov/unlimlogs I was trying to implement authentication that is explained in Next.js documentation... but what should I do to get roles of current session in client components ? Check Doc: https://nextjs.org/docs/app/building-your-application/authentication |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You cannot query prisma in client components.
Options:
In your particular case, I can't see why AppSidebar can not be a Server Component. Try to remove "use client" and fetch data directly there. export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
const admin = await getAdmin();
...
} |
Beta Was this translation helpful? Give feedback.
-
I see, that's because you are passing the icons as functions, and functions can not get passed from server to client components as they are not serializable. In this case, you can keep In your case, export default async function Layout({
children,
}: {
children: React.ReactNode;
}) {
const admin = await getAdmin();
return (
<SidebarProvider>
<AppSidebar variant="inset" admin={admin} />
...
</SidebarProvider>
);
} "use client"
...
export function AppSidebar({ admin, ...props }) {
...
} |
Beta Was this translation helpful? Give feedback.
I see, that's because you are passing the icons as functions, and functions can not get passed from server to client components as they are not serializable.
In this case, you can keep
AppSidebar
a client component, and instead move data fetching to the parent server component.In your case,
app/cabinet/layout.tsx
.Fetch admin there and pass it to the sidebar.