Skip to content
Back to skills

Authentication

ASecurity

Secure token storage (HttpOnly Cookies) and Middleware patterns.

  • 8 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 8, 2026
ai-agentsnextjssecurityperformance

Works with

  • cli

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned September 8, 2026

npx -y skills add ngxtm/devkit --skill authentication --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Authentication?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Authentication
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ngxtm-authentication/badge)](https://www.skillsdirectory.com/skills/ngxtm-authentication)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: Next.js Authentication
description: Secure token storage (HttpOnly Cookies) and Middleware patterns.
metadata:
  labels: [nextjs, auth, security, cookies]
  triggers:
    files: ['middleware.ts', '**/auth.ts', '**/login/page.tsx']
    keywords: [cookie, jwt, session, localstorage, auth]
---

# Authentication & Token Management

## **Priority: P0 (CRITICAL)**

Use **HttpOnly Cookies** for token storage. **Never** use LocalStorage.

## Key Rules

1. **Storage**: Use `cookies().set()` with `httpOnly: true`, `secure: true`, `sameSite: 'lax'`.
   - _Reference_: [Auth Implementation](references/auth-implementation.md) (See "Setting Tokens").
2. **Access**: Read tokens in Server Components via `cookies().get()`.
   - _Reference_: [Auth Implementation](references/auth-implementation.md) (See "Reading Tokens").
3. **Protection**: Guard routes in `middleware.ts` before rendering.
   - _Reference_: [Auth Implementation](references/auth-implementation.md) (See "Middleware Protection").

## Anti-Pattern: LocalStorage

- **Security Risk**: Vulnerable to XSS.
- **Performance Hit**: Incompatible with Server Components (RSC). Forces client hydration and causes layout shift.

Files in this skill

  • SKILL.md1.2 KB
  • references/auth-implementation.md1.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…