Chat / backend /src /modules /auth /auth.controller.ts
kishankrish19's picture
Deploy Stillwave fullstack clean
b0798af
Raw History Blame Contribute Delete
2.37 kB
import {
Controller,
Post,
Get,
Body,
Param,
Query,
UseGuards,
Req,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { AuthService } from './auth.service';
import { SignupDto } from './dto/signup.dto';
import {
LoginDto,
ForgotPasswordDto,
ResetPasswordDto,
RefreshTokenDto,
} from './dto/login.dto';
import { JwtAuthGuard } from './jwt-auth.guard';
@ApiTags('Authentication')
@Controller('auth')
export class AuthController {
constructor(private readonly authService: AuthService) {}
@Post('signup')
@ApiOperation({ summary: 'Register a new user account' })
signup(@Body() dto: SignupDto) {
return this.authService.signup(dto);
}
@Post('login')
@ApiOperation({ summary: 'Authenticate user & return JWT tokens' })
login(@Body() dto: LoginDto) {
return this.authService.login(dto);
}
@Post('logout')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Revoke active refresh token session' })
logout(@Req() req: any) {
return this.authService.logout(req.user.userId, req.user.sessionId);
}
@Post('refresh-token')
@ApiOperation({ summary: 'Exchange valid refresh token for access token' })
refreshToken(@Body() dto: RefreshTokenDto) {
return this.authService.refreshToken(dto.refresh_token);
}
@Post('forgot-password')
@ApiOperation({ summary: 'Request password-reset link' })
forgotPassword(@Body() dto: ForgotPasswordDto) {
return this.authService.forgotPassword(dto.email);
}
@Post('reset-password')
@ApiOperation({ summary: 'Reset password using token' })
resetPassword(@Body() dto: ResetPasswordDto) {
return this.authService.resetPassword(dto.reset_token, dto.new_password);
}
@Get('oauth/:provider')
@ApiOperation({ summary: 'Initiate OAuth provider login' })
getOAuthUrl(@Param('provider') provider: string) {
return this.authService.getOAuthUrl(provider);
}
@Get('oauth/callback')
@ApiOperation({ summary: 'OAuth redirect callback handler' })
handleOAuthCallback(@Query('code') code: string) {
return this.authService.getOAuthUrl('callback');
}
@Get('me')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Get current authenticated profile' })
getMe(@Req() req: any) {
return this.authService.getMe(req.user.userId);
}
}