Checkers
Learn about the authentication checkers available in Better Auth
Checkers ✅
Checkers are functions that verify authentication state in your Next.js application. They are returned by the createAuthLayer
function and can be used in both server and client components.
Available Checkers 🎯
isAuth
Check if a user is authenticated:
isGuest
Check if a user is a guest (not authenticated):
isUser
Check if a user is logged in:
isAdmin
Check if a user is an admin:
isRole
Check if a user has a specific role:
Usage Examples 📝
Server Components
API Routes
Client Components
Best Practices 📚
- Use checkers for conditional rendering
- Cache authentication state when possible
- Handle loading states appropriately
- Consider using guards for route protection
- Use appropriate error handling