Nextjs Client Cookie Pattern
Pattern for client components calling server actions that set Next.js cookies on click or submit.
- CCM score
- 43 of 100
- skills.sh installs
- 328
- GitHub stars
- 116
- last updated
- Aug 21, 2026
Own this skill? Claim it
What it does
- Covers the two-file pattern: a
'use client'component with an onClick handler or form action, and a'use server'action that sets the cookie - Includes complete examples for a theme toggle, a cookies-accepted banner, a language selector, and a form-based preferences save
- Shows cookie options such as
httpOnly,secure,sameSite,maxAge, andpath, plus a login example that redirects after setting a session cookie - Designed for authentication, preference, and session features where a client-side trigger must modify server-side cookies
Install
$ npx -y skills add wsimmonds/claude-nextjs-skills --skill nextjs-client-cookie-pattern -yInstalls into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.
Files
Next.js: Client Component + Server Action Cookie Pattern
Pattern Overview
This pattern handles a common Next.js requirement: client-side interaction (button click) that needs to set server-side cookies.
Why Two Files?
- Client components (
'use client') can have onClick handlers - Only server code can set cookies (security requirement)
- Solution: Client component calls a server action that sets cookies
The Pattern
Scenario: A button that sets a cookie when clicked
File 1: Client Component (app/CookieButton.tsx)
- Has
'use client'directive - Has onClick handler
- Imports and calls server action
File 2: Server Action (app/actions.ts)
- Has
'use server'directive - Uses
cookies()fromnext/headers - Sets the cookie
Complete Implementation
File 1: Client Component
// app/CookieButton.tsx
'use client';
import { setPreference } from './actions';
export default function CookieButton() {
const handleClick = async () => {
await setPreference('dark-mode', 'true');
};
return (
<button onClick={handleClick}>
Enable Dark Mode
</button>
);
}
File 2: Server Action
Details
- Repository
- github.com/wsimmonds/claude-nextjs-skills
- Categories
- Frontend & UI Code, Backend & APIs
- First seen
- Jun 3, 2026
Questions
What does the nextjs-client-cookie-pattern skill do?
The nextjs-client-cookie-pattern skill teaches a two-file pattern where a client component with onClick or form submission calls a server action that sets cookies in Next.js. It covers the reason only server code can set cookies, plus examples such as theme toggles, cookie banners and language preferences.
How do I install the nextjs-client-cookie-pattern skill?
Run npx -y skills add wsimmonds/claude-nextjs-skills --skill nextjs-client-cookie-pattern -y in a project. The nextjs-client-cookie-pattern skill then lets the agent build client components that call server actions to set or modify cookies.
Where does nextjs-client-cookie-pattern stand in the Frontend & UI Code category?
nextjs-client-cookie-pattern is in the Frontend & UI Code category, next to vercel-react-best-practices, web-design-guidelines, design-taste-frontend, vercel-composition-patterns and lark-apps. Its focus is narrower, covering only how client interactions set server-side cookies in Next.js.
When should I use the nextjs-client-cookie-pattern skill?
Use nextjs-client-cookie-pattern when building authentication, preferences or session management where a client-side trigger must set or modify server-side cookies. The skill also covers cookie options such as httpOnly, secure, sameSite and maxAge.
More from wsimmonds/claude-nextjs-skills
All 9Similar to Nextjs Client Cookie Pattern
More Frontend & UI Codenextjs-server-client-componentswsimmonds/claude-nextjs-skills366 installsGuide for choosing Server or Client Components in Next.js App Router, with cookies, headers, and searchParams handling.
nextjs-server-navigationwsimmonds/claude-nextjs-skills307 installsServer-side navigation in Next.js with Link and redirect(), without unnecessary 'use client' conversion.
clerk-nextjs-patternsclerk/skills57.4K installsAdvanced Next.js patterns for Clerk auth covering middleware, Server Actions, and user-scoped caching.
nextjs-app-routergiuseppe-trisciuoglio/developer-kit4.2K installsModern App Router guide for Next.js 16+ covering Server Components, Server Actions, caching, and routing conventions.
nextjs-corebobmatnyc/claude-mpm-skills375 installsApp Router patterns for Server Components, Server Actions, route handlers, and explicit caching with revalidation.
nextjs-best-practicessickn33/agentic-awesome-skills7.6K installsNext.js App Router principles covering Server vs Client Components, data fetching, routing, caching, and Server Actions.