import { Body, Controller, Get, Headers, Param, Post, UnauthorizedException } from '@nestjs/common'; import { AuthService } from './auth.service'; import { LoginDto } from './dto.login.dto'; import { RefreshDto } from './dto.refresh.dto'; import { LogoutDto } from './dto.logout.dto'; @Controller('auth') export class AuthController { constructor(private readonly authService: AuthService) {} @Post('login') login(@Body() body: LoginDto) { return this.authService.login(body); } @Post('refresh') refresh(@Body() body: RefreshDto) { return this.authService.refresh(body.refreshToken); } @Post('logout') logout(@Body() body: LogoutDto) { return this.authService.logout(body.refreshToken); } @Get('me/guilds') meGuilds(@Headers('authorization') authorization?: string) { const token = authorization?.startsWith('Bearer ') ? authorization.slice(7) : ''; if (!token) throw new UnauthorizedException('missing bearer token'); return this.authService.listMyGuilds(token); } @Post('me/guilds/join') joinGuild(@Headers('authorization') authorization: string | undefined, @Body() body: { guildNodeId?: string }) { const token = authorization?.startsWith('Bearer ') ? authorization.slice(7) : ''; if (!token) throw new UnauthorizedException('missing bearer token'); return this.authService.joinGuild(token, String(body?.guildNodeId ?? '')); } @Get('guilds/:guildNodeId/members') guildMembers(@Headers('authorization') authorization: string | undefined, @Param('guildNodeId') guildNodeId: string) { const token = authorization?.startsWith('Bearer ') ? authorization.slice(7) : ''; if (!token) throw new UnauthorizedException('missing bearer token'); return this.authService.listGuildMembers(token, guildNodeId); } @Post('introspect') introspect(@Body() body: { token?: string; guildNodeId?: string }) { return this.authService.introspectGuildToken(body?.token ?? '', body?.guildNodeId ?? ''); } }