You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.4 KiB
33 lines
1.4 KiB
import { Body, Controller, Get, Post, Request, UseGuards } from '@nestjs/common';
|
|
import { AuthService } from './auth.service';
|
|
import { CreateUserDto } from 'src/users/dto/create-user.dto';
|
|
import { LoginUserDto } from 'src/auth/dto/login-user.dto';
|
|
import { SuccessResponseDto } from 'src/common/dto/sucees-response.dto';
|
|
import { LoginResponseDto } from './dto/login-response.dto';
|
|
import { UsersService } from 'src/users/users.service';
|
|
import { JwtAuthGuard } from './jwt-auth.guard';
|
|
import { UserInfoResponseDto } from 'src/users/dto/user-info-response.dto';
|
|
|
|
@Controller('auth')
|
|
export class AuthController {
|
|
constructor(private readonly authService: AuthService, private userService: UsersService) {}
|
|
|
|
@Post('signup')
|
|
async signup(@Body() dto: CreateUserDto): Promise<SuccessResponseDto> {
|
|
const user = await this.authService.signup(dto);
|
|
return SuccessResponseDto.ok();
|
|
}
|
|
|
|
@Post('login')
|
|
async login(@Body() dto: LoginUserDto): Promise<SuccessResponseDto<LoginResponseDto>> {
|
|
const loginUser = await this.authService.login(dto);
|
|
return SuccessResponseDto.of(loginUser);
|
|
}
|
|
|
|
@Get('me')
|
|
@UseGuards(JwtAuthGuard)
|
|
async getMe(@Request() req): Promise<SuccessResponseDto<UserInfoResponseDto>> {
|
|
const userInfo = await this.userService.findUserInfoByIdOrFail(req.user.userId);
|
|
return SuccessResponseDto.of(userInfo);
|
|
}
|
|
}
|
|
|