UNPKG

nuxt-users

Version:

A comprehensive user management module for Nuxt 3 and Nuxt 4 applications with authentication, authorization, database support, and CLI tools

180 lines (178 loc) 4.53 kB
type DatabaseType = 'sqlite' | 'mysql' | 'postgresql'; type HttpMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH'; type Permission = string | { path: string; methods: HttpMethod[]; }; type DatabaseConfig = { path?: string; host?: string; port?: number; user?: string; password?: string; database?: string; }; interface RuntimeModuleOptions { connector?: { name: DatabaseType; options: DatabaseConfig; }; /** * Base path for all module API endpoints * @default '/api/nuxt-users' */ apiBasePath?: string; tables?: { migrations?: string; users?: string; personalAccessTokens?: string; passwordResetTokens?: string; }; /** * Mailer configuration options for sending emails (e.g., password resets) * Uses nodemailer */ mailer?: MailerOptions; /** * Base URL for password reset links * @default 'http://localhost:3000' // Example, will be set in module defaults */ passwordResetBaseUrl?: string; /** * Skip database checks during module setup to prevent hanging * @default false */ auth?: { /** * Whitelisted routes that do not require authentication * @default ['/login'] * @example ['/login', '/register'] */ whitelist?: string[]; /** * Token expiration time in minutes * @default 1440 */ tokenExpiration?: number; /** * Role-based permissions configuration * @default {} * @example { * admin: ['*'], // admin can access everything * user: ['/profile', '/api/nuxt-users/me'], * moderator: ['/admin/*', '/api/admin/*'] * } */ permissions?: Record<string, (string | Permission)[]>; }; /** * Password validation configuration */ passwordValidation?: { /** * Minimum password length * @default 8 */ minLength?: number; /** * Require uppercase letters * @default true */ requireUppercase?: boolean; /** * Require lowercase letters * @default true */ requireLowercase?: boolean; /** * Require numbers * @default true */ requireNumbers?: boolean; /** * Require special characters * @default true */ requireSpecialChars?: boolean; /** * Prevent common passwords * @default true */ preventCommonPasswords?: boolean; }; } interface ModuleOptions { connector: { name: DatabaseType; options: DatabaseConfig; }; apiBasePath: string; tables: { migrations: string; users: string; personalAccessTokens: string; passwordResetTokens: string; }; mailer?: MailerOptions; passwordResetBaseUrl?: string; auth: { whitelist: string[]; tokenExpiration: number; permissions: Record<string, (string | Permission)[]>; }; passwordValidation: { minLength: number; requireUppercase: boolean; requireLowercase: boolean; requireNumbers: boolean; requireSpecialChars: boolean; preventCommonPasswords: boolean; }; } interface MailerOptions { host: string; port: number; secure?: boolean; auth: { user: string; pass: string; }; defaults?: { from: string; }; } interface User { id: number; email: string; name: string; password: string; role: string; created_at: string; updated_at: string; last_login_at?: string; } type UserWithoutPassword = Omit<User, 'password'>; interface PersonalAccessToken { id: number; tokenable_type: string; tokenable_id: number; name: string; token: string; abilities?: string; last_used_at?: string; expires_at?: string; created_at: string; updated_at: string; } interface PasswordResetToken { id: number; email: string; token: string; created_at: string; } interface LoginFormData { email: string; password: string; rememberMe?: boolean; } export type { LoginFormData as L, ModuleOptions as M, PersonalAccessToken as P, RuntimeModuleOptions as R, User as U, UserWithoutPassword as a, PasswordResetToken as b };