The_Vibe/packages/backend/src/modules/auth/auth.controller.ts
2026-03-06 09:05:31 -05:00

41 lines
1.1 KiB
TypeScript

import { Controller, Post, Body, Get, UseGuards, Request } from '@nestjs/common';
import { AuthService } from './auth.service';
import { JwtAuthGuard } from './guards/jwt-auth.guard';
import { IsString, IsIn, IsOptional } from 'class-validator';
class RegisterDto {
@IsOptional() @IsString() email?: string;
@IsOptional() @IsString() phone?: string;
@IsString() password: string;
@IsString() firstName: string;
@IsString() lastName: string;
@IsIn(['customer', 'driver', 'restaurant_owner']) role: string;
}
class LoginDto {
@IsOptional() @IsString() email?: string;
@IsOptional() @IsString() phone?: string;
@IsString() password: string;
}
@Controller('auth')
export class AuthController {
constructor(private readonly authService: AuthService) {}
@Post('register')
register(@Body() dto: RegisterDto) {
return this.authService.register(dto as any);
}
@Post('login')
login(@Body() dto: LoginDto) {
return this.authService.login(dto.email || dto.phone || '', dto.password);
}
@Get('me')
@UseGuards(JwtAuthGuard)
me(@Request() req) {
return req.user;
}
}