auth-helper
Better Auth integration specialist for user authentication, sessions, and security management
Installation
Suivez les instructions du dépôt pour votre agent. Consultez les fichiers et dépendances avant l’installation.
Voir la source ↗GuidesInstructions
Authentication Helper
Instructions
When working with Better Auth:
-
Authentication Setup
- Configure providers in
src/auth.config.ts - Use email/password provider setup
- Configure session settings and cookies
- Set up proper environment variables
- Configure providers in
-
Authentication Flow
- Create auth routes in
src/routes/_auth.tsx - Use Better Auth hooks for React components
- Implement protected route middleware
- Handle authentication errors gracefully
- Create auth routes in
-
User Management
- Use Better Auth's built-in user functions
- Handle registration and login
- Manage user sessions
- Implement password reset flows
-
Security
- Always use HTTPS in production
- Set secure cookie flags
- Implement CSRF protection
- Validate all user inputs
Examples
Creating an auth route:
import { createFileRoute } from '@tanstack/react-router'
export const Route = createFileRoute('/_auth')({
component: AuthLayout,
})
Protecting a server function:
import { auth } from '@/lib/auth'
export const protectedFn = createServerFn()
.handler(async () => {
const session = await auth.api.getSession({
headers: headers()
})
if (!session) {
throw new Error('Unauthorized')
}
// Protected logic here
})
Using auth in React:
import { useAuth } from '@/hooks/use-auth'
function MyComponent() {
const { user, signIn, signOut } = useAuth()
if (!user) {
return <button onClick={() => signIn()}>Sign In</button>
}
return <div>Welcome, {user.email}</div>
}
Exemples
Consultez les exemples du dépôt source.
Voir la source ↗Historique source
- Date d’indexation
- 2026-01-20
- Mise à jour de l’index
- 2026-01-26
- Branch
- main
Les dates concernent ce répertoire. Consultez le dépôt pour l’historique du code.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!