cookies in server action cause error
Answered
Alex posted this in #help-forum
AlexOP
for my auth I have to get the session from a cookie in a server action. on page load I recieve this error:
I am not using the pages directory nor using a client component.
./src/auth/lucia.ts
Error:
× You're importing a component that needs next/headers. That only works in a Server Component which is not supported in the pages/ directory. Read more: https://nextjs.org/docs/getting-started/
│ react-essentials#server-components
│
│
â•â”€[/........./src/auth/lucia.ts:3:1]
3 │ import { PrismaAdapter } from "@lucia-auth/adapter-prisma";
4 │
5 │ import prisma from "@/db/client";
6 │ import { cookies } from "next/headers";
· ───────────────────────────────────────
7 │ import { cache } from "react";
8 │ import { redirect } from "next/navigation";
╰────
Import trace for requested module:
./src/auth/lucia.ts
./src/app/(webapp)/admin/events/actions.tsx
./src/app/(webapp)/admin/events/form.tsx
I am not using the pages directory nor using a client component.
Answered by Alex
found the error, a "use server"; in another file was missing. weird, because I havn't touched this file in a long time and it has never caused any issues