42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
|
|
import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common'
|
||
|
|
import { ApiTags } from '@nestjs/swagger'
|
||
|
|
import { ResponseMapper } from '../common/response/response-mapper'
|
||
|
|
import { AuthService } from './auth.service'
|
||
|
|
import { CurrentUser } from './current-user.decorator'
|
||
|
|
import { RefreshTokenDto } from './dto/refresh-token.dto'
|
||
|
|
import { SendCodeDto } from './dto/send-code.dto'
|
||
|
|
import { VerifyCodeDto } from './dto/verify-code.dto'
|
||
|
|
import { JwtAuthGuard } from './jwt-auth.guard'
|
||
|
|
|
||
|
|
@ApiTags('auth')
|
||
|
|
@Controller('auth')
|
||
|
|
export class AuthController {
|
||
|
|
constructor(private readonly auth: AuthService) {}
|
||
|
|
|
||
|
|
@Post('send-code')
|
||
|
|
async sendCode(@Body() dto: SendCodeDto) {
|
||
|
|
return this.auth.sendCode(dto)
|
||
|
|
}
|
||
|
|
|
||
|
|
@Post('login')
|
||
|
|
async login(@Body() dto: VerifyCodeDto) {
|
||
|
|
return this.auth.loginWithCode(dto)
|
||
|
|
}
|
||
|
|
|
||
|
|
@Post('refresh')
|
||
|
|
async refresh(@Body() dto: RefreshTokenDto) {
|
||
|
|
return this.auth.refreshToken(dto)
|
||
|
|
}
|
||
|
|
|
||
|
|
@Post('logout')
|
||
|
|
async logout(@Body() dto: RefreshTokenDto) {
|
||
|
|
return this.auth.logout(dto.refreshToken)
|
||
|
|
}
|
||
|
|
|
||
|
|
@Get('me')
|
||
|
|
@UseGuards(JwtAuthGuard)
|
||
|
|
async me(@CurrentUser() user: any) {
|
||
|
|
return ResponseMapper.single(user)
|
||
|
|
}
|
||
|
|
}
|