Add complete user authentication with NextAuth.js supporting: - Email/password credentials authentication - OAuth providers (GitHub, Google) with optional configuration - JWT-based session management with 30-day expiry - Role-based access control (USER, GROWER, FARM_MANAGER, ADMIN) - Permission system with granular access control - Secure password hashing with bcrypt (12 rounds) - Rate limiting on auth endpoints - Password reset flow with secure tokens - Email verification system Files added: - lib/auth/: Core auth library (types, permissions, context, hooks, middleware) - pages/api/auth/: Auth API routes (NextAuth, register, forgot-password, verify-email) - pages/auth/: Auth pages (signin, signup, forgot-password, reset-password, verify-email) - components/auth/: Reusable auth components (LoginForm, RegisterForm, AuthGuard, etc.) Updated _app.tsx to include SessionProvider for auth state management.
30 lines
653 B
TypeScript
30 lines
653 B
TypeScript
// Types
|
|
export * from './types'
|
|
|
|
// Permissions
|
|
export * from './permissions'
|
|
|
|
// Context and hooks
|
|
export { AuthProvider, useAuth, withAuth as withAuthComponent, AuthContext } from './AuthContext'
|
|
export { useAuth as useAuthHook, usePermission, useRole, useRequireAuth } from './useAuth'
|
|
|
|
// API middleware
|
|
export {
|
|
withAuth,
|
|
withRole,
|
|
withPermission,
|
|
withAnyPermission,
|
|
withAllPermissions,
|
|
withRateLimit,
|
|
checkRateLimit,
|
|
} from './withAuth'
|
|
export type { AuthenticatedRequest } from './withAuth'
|
|
|
|
// Role-based middleware
|
|
export {
|
|
requireRole,
|
|
requireAdmin,
|
|
requireFarmManager,
|
|
requireGrower,
|
|
requireUser,
|
|
} from './withRole'
|