# authentication-best-practices

The authentication-best-practices Claude Code skill covers Better Auth sessions, route protection, and sign-in flows. It activates when a task involves access control for pages or APIs.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode, Windsurf (Devin Desktop), Claude.ai · 106 installs · ★ 23 repo stars
- Author: andrelandgraf
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/andrelandgraf/fullstackrecipes/tree/HEAD/skills/authentication-best-practices/SKILL.md
- Updated: 2026-06-08
- Security check: automated, 2026-11-17 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/skills/authentication-best-practices

## What it does

The skill explains how to read Better Auth sessions in client components and on the server, protect routes, and handle sign-in, sign-up, and sign-out. Client components use hooks from `@/lib/auth/client`; server code checks sessions with `auth.api.getSession` and request headers.

Unauthenticated visitors can be redirected away from protected pages, while signed-in users can be sent away from authentication pages. User-specific data can be fetched in parallel after the session check. Complete the Better Auth Setup recipe first.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add andrelandgraf/fullstackrecipes --skill authentication-best-practices -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/authentication-best-practices/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/authentication-best-practices/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add andrelandgraf/fullstackrecipes --skill authentication-best-practices -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/authentication-best-practices/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add andrelandgraf/fullstackrecipes --skill authentication-best-practices -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/authentication-best-practices/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install andrelandgraf/fullstackrecipes skills/authentication-best-practices
```

2. **Manually: put the files in place**
- File: `.github/skills/authentication-best-practices/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add andrelandgraf/fullstackrecipes --skill authentication-best-practices -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/andrelandgraf/fullstackrecipes --path skills/authentication-best-practices
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/authentication-best-practices/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add andrelandgraf/fullstackrecipes --skill authentication-best-practices -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/andrelandgraf/fullstackrecipes/tree/HEAD/skills/authentication-best-practices/SKILL.md

## When to use it
- check a user's session on the server
- block unauthenticated access to a page or API
- redirect signed-in users away from authentication pages
- wire up Better Auth sign-in, sign-up, and sign-out

## Example prompts
- Protect the profile page with a Better Auth session check.
- Add email sign-in and user registration.
- Redirect signed-in users away from the sign-in page.

## Similar
- [two-factor-authentication-best-practices](https://affpapa.org/en/nevibecode/skills/two-factor-authentication-best-practices.md) — skill · 37300 installs
- [authentication](https://affpapa.org/en/nevibecode/skills/codewithmukesh-authentication.md) — skill · 4000 installs
- [nextjs-authentication](https://affpapa.org/en/nevibecode/skills/nextjs-authentication.md) — skill · 4000 installs
- [nextauth-authentication](https://affpapa.org/en/nevibecode/skills/nextauth-authentication.md) — skill · 1200 installs
- [catalyst-authentication](https://affpapa.org/en/nevibecode/skills/catalyst-authentication.md) — skill · 1200 installs
- [auth0-authentication](https://affpapa.org/en/nevibecode/skills/auth0-authentication.md) — skill · 740 installs

From the same set: [andrelandgraf/fullstackrecipes](https://affpapa.org/en/nevibecode/by/andrelandgraf/fullstackrecipes.md) — 9 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
