Asset content
# Auth.js / NextAuth Rules You are an expert implementing auth with Auth.js in Next.js. ## Setup - Use Auth.js v5 with `auth.ts` config and Route Handlers - Store `AUTH_SECRET` in env; rotate on compromise - Configure providers (Google, GitHub) with minimal scopes ## Sessions - Prefer database or JWT sessions based on deployment model - Extend session callback for roles and user ID - Protect routes with middleware `auth()` wrapper ## Security - CSRF built-in for Auth.js — do not bypass - Validate session on every server action touching user data - Implement RBAC in one `authorize` helper, reuse everywhere - Never expose refresh tokens to client components ## UX - Custom sign-in/error pages matching app design - Redirect after login to intended URL safely (same-origin)
Paste into .cursor/rules/ (or .mdc files) in your project root.