Template base para proyectos SaaS multi-tenant. Estructura inicial: - apps/backend (NestJS API) - apps/frontend (React/Vite) - apps/database (PostgreSQL DDL) - docs/ (Documentación) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
52 lines
2.0 KiB
TypeScript
52 lines
2.0 KiB
TypeScript
import { Repository, DataSource } from 'typeorm';
|
|
import { JwtService } from '@nestjs/jwt';
|
|
import { ConfigService } from '@nestjs/config';
|
|
import { User, Session, Token } from '../entities';
|
|
import { RegisterDto, LoginDto, ChangePasswordDto } from '../dto';
|
|
export interface AuthResponse {
|
|
user: Partial<User>;
|
|
accessToken: string;
|
|
refreshToken: string;
|
|
}
|
|
export interface JwtPayload {
|
|
sub: string;
|
|
email: string;
|
|
tenant_id: string;
|
|
}
|
|
export declare class AuthService {
|
|
private readonly userRepository;
|
|
private readonly sessionRepository;
|
|
private readonly tokenRepository;
|
|
private readonly jwtService;
|
|
private readonly configService;
|
|
private readonly dataSource;
|
|
constructor(userRepository: Repository<User>, sessionRepository: Repository<Session>, tokenRepository: Repository<Token>, jwtService: JwtService, configService: ConfigService, dataSource: DataSource);
|
|
register(dto: RegisterDto, tenantId: string, ip?: string, userAgent?: string): Promise<AuthResponse>;
|
|
login(dto: LoginDto, tenantId: string, ip?: string, userAgent?: string): Promise<AuthResponse>;
|
|
logout(userId: string, sessionToken: string): Promise<void>;
|
|
logoutAll(userId: string): Promise<void>;
|
|
refreshToken(refreshToken: string, ip?: string, userAgent?: string): Promise<{
|
|
accessToken: string;
|
|
refreshToken: string;
|
|
}>;
|
|
changePassword(userId: string, dto: ChangePasswordDto): Promise<{
|
|
message: string;
|
|
}>;
|
|
requestPasswordReset(email: string, tenantId: string): Promise<{
|
|
message: string;
|
|
}>;
|
|
resetPassword(token: string, newPassword: string, tenantId: string): Promise<{
|
|
message: string;
|
|
}>;
|
|
verifyEmail(token: string, tenantId: string): Promise<{
|
|
message: string;
|
|
}>;
|
|
validateUser(userId: string): Promise<User | null>;
|
|
getProfile(userId: string): Promise<Partial<User>>;
|
|
private generateTokens;
|
|
private createVerificationToken;
|
|
private hashToken;
|
|
private sanitizeUser;
|
|
private detectDeviceType;
|
|
}
|