auth-handler
Manage authentication, authorization, and user sessions. Use when dealing with login, sign-up, API protection, middleware, or user data fetching.
Installation
Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.
View source ↗GuidesSkill instructions
Auth Handler
Instructions
1. API Route Protection
-
Standard Routes: Use
withAuthRequired.export default withAuthRequired(async (req, { session, getUser }) => { ... }) -
Super Admin Routes: Use
withSuperAdminAuthRequired. -
Cron Jobs: Use
cronAuthRequired. - Defense in Depth: Do NOT rely solely on middleware. Always implement individual route protection.
2. Frontend Data Access
-
Client Components: Use
useUser()hook (SWR). -
Restriction: NEVER use
useSessionfromnext-auth/react.
3. Server-Side Data Access
-
Check Auth: Import
authfrom@/auth. -
Get Plan: Use
getUserPlan(session.user.id).session.useris minimal.
Reference
For architecture details, key files, and debugging tips, see reference.md.
Examples
Read the usage examples in the source repository.
View source ↗Source history
- Indexed on
- 2026-01-20
- Index updated
- 2026-01-28
- Branch
- main
Index and sync dates describe this directory. View the source repository for code history.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!