#cookies in server action cause error

6 messages · Page 1 of 1 (latest)

solemn marlin
#

for my auth I have to get the session from a cookie in a server action. on page load I recieve this error:

./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.

molten jasperBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

solemn marlin
#

using lucia by the way

thin pilot
solemn marlin
#

3

#

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