Next.js Discord

Discord Forum

Next.js Authentication Guide Issues

Unanswered
Hunting wasp posted this in #help-forum
Open in Discord
Hunting waspOP
I'm trying to faithfully follow the next.js authentication guide to perform auth using a server action, which sets cookies using server side headers (as shown in the guide)

However, when I attempt to follow the steps, I'm met with an error about using server api in a client component, which I puzzling because it appears to be shown as correct by the docs

"You're importing a component that needs "server-only". That only works in a Server Component but one of its parents is marked with "use client", so it's a Client Component."

I've pushed up a POC example which started from create-next-app, and only added the relevant files from the authentication guide: https://github.com/bhurlow/nextjs-auth-example

I assume its possible to call a server action from a use client component like this: https://github.com/bhurlow/nextjs-auth-example/blob/main/app/ui/login-form.tsx#L7. Any suggestions?

1 Reply

Hunting waspOP
for some context, I'm trying to identify a "working" version of setting cookies from the server action (again, as recommended by the guide), because my actual application is setting cookies on the client side and I'm seeing issues with stale router cache behavior there – I suspect that the server action should be doing more correct invalidation