localgreenchain/lib/auth/types.ts
Claude 39b6081baa
Implement comprehensive authentication system (Agent 1)
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.
2025-11-23 03:52:09 +00:00

76 lines
1.3 KiB
TypeScript

import { DefaultSession, DefaultUser } from 'next-auth'
import { JWT, DefaultJWT } from 'next-auth/jwt'
export enum UserRole {
USER = 'USER',
GROWER = 'GROWER',
FARM_MANAGER = 'FARM_MANAGER',
ADMIN = 'ADMIN',
}
export interface AuthUser {
id: string
email: string
name?: string | null
image?: string | null
role: UserRole
emailVerified?: Date | null
}
declare module 'next-auth' {
interface Session extends DefaultSession {
user: AuthUser
}
interface User extends DefaultUser {
role: UserRole
emailVerified?: Date | null
}
}
declare module 'next-auth/jwt' {
interface JWT extends DefaultJWT {
id: string
role: UserRole
emailVerified?: Date | null
}
}
export interface RegisterInput {
email: string
password: string
name?: string
role?: UserRole
}
export interface LoginInput {
email: string
password: string
}
export interface ForgotPasswordInput {
email: string
}
export interface ResetPasswordInput {
token: string
password: string
}
export interface VerifyEmailInput {
token: string
}
export interface AuthResponse {
success: boolean
message: string
user?: AuthUser
error?: string
}
export interface TokenPayload {
userId: string
email: string
type: 'email_verification' | 'password_reset'
expiresAt: number
}