Skip to content
Back to skills

Better Auth

ASecurity

Better Auth в Next.js 16 + ZenStack: конфиг betterAuth(), OAuth (Google, Яндекс, VK ID), плагины (organization, emailOTP, anonymous, oauth-provider), proxy.ts, роли. Загружай ДО правки lib/auth.ts или моделей Account/Session и когда любой /api/auth/* падает 500 без строки в логах, SCHEMA_MISMATCH при старте, вход ломается после bun update better-auth, не приходит emailOTP, в dev «Invalid Base64 character» из-за чужой сессии.

  • 5 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added October 20, 2026
developmenttypescriptgobashnextjsnodeapisecurity

Works with

  • cli
  • api

Security analysis

A100/100

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

Scanned October 20, 2026

npx -y skills add kamiletar/letar --skill better-auth --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Better Auth?

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

Security grade badge for Better Auth
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/kamiletar-better-auth/badge)](https://www.skillsdirectory.com/skills/kamiletar-better-auth)

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: better-auth
description: |
  Better Auth в Next.js 16 + ZenStack: конфиг betterAuth(), OAuth (Google, Яндекс, VK ID), плагины (organization, emailOTP, anonymous, oauth-provider), proxy.ts, роли. Загружай ДО правки lib/auth.ts или моделей Account/Session и когда любой /api/auth/* падает 500 без строки в логах, SCHEMA_MISMATCH при старте, вход ломается после bun update better-auth, не приходит emailOTP, в dev «Invalid Base64 character» из-за чужой сессии.
---

# Better Auth Specialist

Эксперт по аутентификации Better Auth в контексте Next.js 16, ZenStack и Prisma.

## ⚠️ Ловушки (разборы в доках)

- [better-auth-prismaadapter-zenstack-incompatibility](/.claude/docs/better-auth-prismaadapter-zenstack-incompatibility.md) — `/api/auth/*` падает 500 без строк в логах: `prismaAdapter()` не принимает ZenStack-клиент
- [better-auth-plugin-modelname-casing-schema-mismatch](/.claude/docs/better-auth-plugin-modelname-casing-schema-mismatch.md) — `SCHEMA_MISMATCH` при старте называет отсутствующей таблицу, которая есть
- [better-auth-1.7-oidc-provider-removed](/.claude/docs/better-auth-1.7-oidc-provider-removed.md) — `bun update` поднимает better-auth до 1.7: `oidcProvider` убран из ядра
- [better-auth-1.7-account-issuer-field](/.claude/docs/better-auth-1.7-account-issuer-field.md) — тот же релиз требует поле `issuer` в модели `Account`
- [better-auth-emailotp-silent-send-failure](/.claude/docs/better-auth-emailotp-silent-send-failure.md) — `emailOTP` не пробрасывает сбой отправки письма
- [better-auth-localhost-cookie-jar-collision](/.claude/docs/better-auth-localhost-cookie-jar-collision.md) — dev-серверы делят cookie-jar `localhost`: `Invalid Base64 character`
- [better-auth-vk-id-migration-and-linksocial-pitfalls](/.claude/docs/better-auth-vk-id-migration-and-linksocial-pitfalls.md) — VK ID вместо legacy `oauth.vk.com`; `linkSocial()` без email

## Когда использовать

- Настройка аутентификации в новом приложении
- **Миграция с NextAuth/Auth.js на Better Auth** 🔥
- Добавление OAuth провайдеров (Google, Yandex, VK)
- Настройка защиты роутов (proxy.ts)
- Работа с сессиями и ролями
- Интеграция с ZenStack access policies
- Добавление плагинов (2FA, Admin, Organization)
- Troubleshooting auth проблем

## Паттерны проекта

- **Session-based** аутентификация (сессии в БД, не JWT)
- **proxy.ts** работает в Node.js Runtime (полный доступ к БД)
- **ZenStack** для row-level access control через `@@allow`/`@@deny`
- **Enhanced Prisma** клиент применяет политики автоматически

## Quick Reference

### Получение сессии (сервер)

```typescript
import { auth } from '@/lib/auth'
import { headers } from 'next/headers'

const session = await auth.api.getSession({ headers: await headers() })
```

### Получение сессии (клиент)

```typescript
import { useSession } from '@/lib/auth-client'

const { data: session, isPending } = useSession()
```

### ZenStack с auth

```typescript
const session = await auth.api.getSession({ headers: await headers() })
const db = getEnhancedPrisma(session?.user)
// Политики @@allow/@@deny применяются автоматически
```

## Ключевые команды

```bash
# Миграция БД (добавление таблиц плагинов)
npx @better-auth/cli migrate

# Генерация схемы (для Prisma)
npx @better-auth/cli generate
```

## Reference файлы

| Файл                                   | Описание                            |
| -------------------------------------- | ----------------------------------- |
| `reference/nextauth-migration.md`      | 🔥 Миграция с NextAuth (ПРИОРИТЕТ!) |
| `reference/nextjs-integration.md`      | Next.js 16 интеграция               |
| `reference/prisma-adapter.md`          | Prisma адаптер и оптимизация        |
| `reference/session-management.md`      | Сессии, кэширование, revoke         |
| `reference/oauth-providers.md`         | Google, Yandex, VK OAuth            |
| `reference/email-password.md`          | Email/пароль, PIN-верификация       |
| `reference/admin-plugin.md`            | Управление пользователями           |
| `reference/organization-plugin.md`     | Организации и команды               |
| `reference/2fa-plugin.md`              | Двухфакторная аутентификация        |
| `reference/hooks-lifecycle.md`         | Before/After хуки                   |
| `reference/security-best-practices.md` | Безопасность production             |
| `reference/troubleshooting.md`         | Типичные проблемы                   |

## Связанная документация

- `.claude/docs/auth.md` — Полная документация по auth в проекте
- `.claude/skills/zenstack-helper/` — Access policies

Files in this skill

  • SKILL.md5.5 KB
  • reference/2fa-plugin.md9.2 KB
  • reference/admin-plugin.md9.4 KB
  • reference/email-password.md11.8 KB
  • reference/hooks-lifecycle.md10.7 KB
  • reference/nextauth-migration.md12.8 KB
  • reference/nextjs-integration.md8.2 KB
  • reference/oauth-providers.md8.1 KB
  • reference/organization-plugin.md11.5 KB
  • reference/prisma-adapter.md7.7 KB
  • reference/security-best-practices.md11.3 KB
  • reference/session-management.md8.1 KB
  • reference/troubleshooting.md8.5 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.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.