Skip to content
Back to skills

Better Auth

ASecurity

Better Auth provides framework-agnostic auth (Next.js, Express, SvelteKit) deeply integrated with modern ORMs like Drizzle and Prisma.

  • 13 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 5, 2026
ai-agentsrustgobashnextjsexpresstestinggitapidatabasesecurity

Works with

  • api

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

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

Scanned September 5, 2026

npx -y skills add ashish7802/awesome-api-skills --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/ashish7802-better-auth/badge)](https://www.skillsdirectory.com/skills/ashish7802-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
# Better Auth API Skill

## Quick Start
Better Auth provides framework-agnostic auth (Next.js, Express, SvelteKit) deeply integrated with modern ORMs like Drizzle and Prisma.

```bash
npm install better-auth
```

## Common Workflows
### OAuth and Magic Links
Configure plugins to enable OAuth (GitHub, Google) or Magic Links. Better Auth natively handles session creation and saves profiles to your database using the provided database adapter.

## Production Patterns
### Two-Factor Authentication
Utilize the `twoFactor` plugin to require TOTP before issuing a valid session cookie. Ensure you construct your UI to gracefully handle the `requires_two_factor` response state.

## Error Recovery
Handle `BetterAuthError`. When creating users, handle conflicts gracefully (e.g., Email already exists) and prompt the user to log in instead.

## Security Notes
Better Auth handles CSRF and secure cookies out of the box. Ensure your `trustedOrigins` configuration accurately reflects your production domains to prevent session hijacking.

## Performance Considerations
Session validation happens on the Edge or Server. Optimize your database queries (e.g., adding indexes to the `session_token` column) to ensure ultra-fast session lookups on every request.

## Testing Guidance
Better Auth can be mocked easily by overriding the `getSession` function in your unit tests, or by provisioning a test database specifically for your test runner.

## Troubleshooting
If sessions randomly invalidate, ensure you are not clearing cookies improperly across subdomains and that the `secret` configuration variable remains static across deployments.

## References
- [Better Auth Docs](https://www.better-auth.com/docs)

## Related Skills
- [Clerk](/skills/clerk)
- [Neon](/skills/neon)

## Why use this skill
Use this when your agent works with **better-auth** — structured patterns beat pasted docs and prevent common hallucinations.

## AI pitfalls
- Using outdated SDK or API versions from training data
- Inventing environment variable names
- Omitting error handling and retry logic

## Production checklist
- [ ] Secrets in environment variables, not source code
- [ ] Error handling and logging in place
- [ ] Rate limits and timeouts configured

## Related skills
- [`clerk`](../clerk/SKILL.md) — related to
- [`neon`](../neon/SKILL.md) — related to

---
> **Last Verified:** 2026-07-02

Files in this skill

  • SKILL.md2.3 KB
  • examples/basic.go55 B
  • examples/basic.py106 B
  • examples/middleware.ts144 B
  • examples/setup.ts227 B
  • prompts/magic-link.md111 B
  • tests/skill.test.ts29 B

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…

Newsletter

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