refactor( iam ): remove local auth service delegate OTP and password reset to IAM

This commit is contained in:
Abubeker Yasin
2026-06-06 10:23:53 +03:00
parent 023522c3fb
commit 254d2a171c
5 changed files with 40 additions and 141 deletions

View File

@@ -1,17 +1,13 @@
import { Body, Controller, Post, HttpCode, HttpStatus, UseGuards, Get, Request, UnauthorizedException } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse, ApiBody, ApiBearerAuth } from '@nestjs/swagger';
import { AuthService } from './auth.service';
import { PassengerAuthService } from './passenger-auth.service';
import { RegisterDto, LoginDto, RequestOtpDto, VerifyOtpDto, RequestPasswordResetDto, ResetPasswordDto } from './auth.dto';
import { RegisterDto, LoginDto } from './auth.dto';
import { JwtGuard } from '../../common/jwt.guard';
@ApiTags('Auth')
@Controller('auth')
export class AuthController {
constructor(
private service: AuthService,
private passengerAuthService: PassengerAuthService,
) {}
constructor(private passengerAuthService: PassengerAuthService) {}
@Post('register')
@ApiOperation({ summary: 'Register new passenger account' })
@@ -32,34 +28,6 @@ export class AuthController {
return this.passengerAuthService.login(dto, req);
}
@Post('otp/request')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Request OTP verification code' })
@ApiResponse({ status: 200, description: 'OTP sent successfully' })
@ApiBody({ type: RequestOtpDto })
requestOtp(@Body() dto: RequestOtpDto) { return this.service.requestOtp(dto); }
@Post('otp/verify')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Verify OTP code' })
@ApiResponse({ status: 200, description: 'OTP verified successfully' })
@ApiBody({ type: VerifyOtpDto })
verifyOtp(@Body() dto: VerifyOtpDto) { return this.service.verifyOtp(dto); }
@Post('password/reset-request')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Request password reset link' })
@ApiResponse({ status: 200, description: 'Password reset email sent' })
@ApiBody({ type: RequestPasswordResetDto })
requestPasswordReset(@Body() dto: RequestPasswordResetDto) { return this.service.requestPasswordReset(dto); }
@Post('password/reset')
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Reset password with token' })
@ApiResponse({ status: 200, description: 'Password reset successfully' })
@ApiBody({ type: ResetPasswordDto })
resetPassword(@Body() dto: ResetPasswordDto) { return this.service.resetPassword(dto); }
@Post('logout')
@HttpCode(HttpStatus.OK)
@UseGuards(JwtGuard)
@@ -89,8 +57,8 @@ export class AuthController {
@ApiResponse({ status: 200, description: 'User profile retrieved successfully' })
@ApiResponse({ status: 401, description: 'Unauthorized' })
getProfile(@Request() req: any) {
const userId = req.user?.id ?? req.user?.userId;
const userId = req.user?.id;
if (!userId) throw new UnauthorizedException('User not authenticated');
return this.service.getProfile(userId);
return this.passengerAuthService.getProfile(userId);
}
}