how can i save cookies in server-components?
Answered
Abdullah Aly posted this in #help-forum
.
9 Replies
Largehead hairtail
'use server';
import { cookies} from 'next/headers';
export const setCookie = async (name: string, value: string) => {
cookies().set(name, value);
};@Abdullah Aly actions.js?
Largehead hairtail
that's your mind, the file name can be anything, actions.js or cookies.js
Thx
@Abdullah Aly .
impossible to do it in server components.
Answer
if you want to mutate cookies on load, you need middleware
cookies() mutation methods such as set only works in server actions (and server actions being called inside server components are not server actions)Ale
Alr