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.
39 lines
1.2 KiB
39 lines
1.2 KiB
import { ApiUseTags, ApiBearerAuth } from '@nestjs/swagger';
|
|
import { Body, Controller, Get, Post, UseGuards } from '@nestjs/common';
|
|
import { LoginDto, TokenDto } from './auth.dto';
|
|
import { AuthService } from './auth.service';
|
|
import { User } from '../../user/user.entity';
|
|
import { UserService } from '../../user/user.service';
|
|
import { UserDtoRegister } from '../../user/user.dto';
|
|
import { CurrentUser } from '../../../decorators/currentUser.decorator';
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
|
|
@ApiUseTags('Auth')
|
|
@Controller()
|
|
export class AuthController {
|
|
constructor(
|
|
private readonly authService: AuthService,
|
|
private readonly userService: UserService,
|
|
) {}
|
|
|
|
@Post('login')
|
|
async signIn(@Body() userLogin: LoginDto): Promise<TokenDto> {
|
|
const token = await this.authService.signIn(
|
|
userLogin.email,
|
|
userLogin.password,
|
|
);
|
|
return { token };
|
|
}
|
|
|
|
@Post('register')
|
|
async registerUser(@Body() userRegister: UserDtoRegister): Promise<User> {
|
|
return this.userService.saveNew(userRegister);
|
|
}
|
|
|
|
@Get('me')
|
|
@ApiBearerAuth()
|
|
@UseGuards(AuthGuard())
|
|
async getMe(@CurrentUser() loggedUser: User) {
|
|
return loggedUser;
|
|
}
|
|
}
|