Files
listify/listify-api/src/auth/auth.controller.ts
Bastian Wagner 01f2aff0be mcp
2026-06-24 13:17:48 +02:00

79 lines
2.0 KiB
TypeScript

import {
Body,
Controller,
Get,
HttpCode,
HttpStatus,
Patch,
Post,
Query,
Req,
UseGuards,
} from '@nestjs/common';
import type { AuthenticatedRequest } from './auth.types';
import { AuthService } from './auth.service';
import { LoginDto } from './dto/login.dto';
import { RefreshTokenDto } from './dto/refresh-token.dto';
import { ResendVerificationDto } from './dto/resend-verification.dto';
import { RegisterDto } from './dto/register.dto';
import { JwtAuthGuard } from './jwt-auth.guard';
@Controller('auth')
export class AuthController {
constructor(private readonly authService: AuthService) {}
@Post('register')
register(@Body() registerDto: RegisterDto) {
return this.authService.register(registerDto);
}
@Get('verify-email')
verifyEmail(@Query('token') token?: string) {
return this.authService.verifyEmail(token);
}
@Post('resend-verification')
@HttpCode(HttpStatus.OK)
resendVerification(@Body() resendVerificationDto: ResendVerificationDto) {
return this.authService.resendVerificationEmail(resendVerificationDto);
}
@Post('login')
@HttpCode(HttpStatus.OK)
login(@Body() loginDto: LoginDto) {
return this.authService.login(loginDto);
}
@Post('refresh')
refresh(@Body() refreshTokenDto: RefreshTokenDto) {
return this.authService.refresh(refreshTokenDto);
}
@Get('me')
@UseGuards(JwtAuthGuard)
me(@Req() request: AuthenticatedRequest) {
return this.authService.getPublicUser(request.user!.sub);
}
@Get('users/search')
@UseGuards(JwtAuthGuard)
searchUsers(
@Req() request: AuthenticatedRequest,
@Query('q') query?: string,
) {
return this.authService.searchUsers(request.user!.sub, query);
}
@Patch('me/onboarding')
@UseGuards(JwtAuthGuard)
updateOnboarding(
@Req() request: AuthenticatedRequest,
@Body() body: { completed?: boolean },
) {
return this.authService.updateOnboardingCompleted(
request.user!.sub,
body.completed === true,
);
}
}