76 lines
2.2 KiB
TypeScript
76 lines
2.2 KiB
TypeScript
// api/src/feacture/auth/auth.controller.ts
|
|
import { Public } from '@/common/decorators';
|
|
import { JwtRefreshGuard } from '@/common/guards/jwt-refresh.guard';
|
|
import { RefreshTokenDto } from '@/features/auth/dto/refresh-token.dto';
|
|
import { SignInUserDto } from '@/features/auth/dto/signIn-user.dto';
|
|
import { SignOutUserDto } from '@/features/auth/dto/signOut-user.dto';
|
|
import { SingUpUserDto } from '@/features/auth/dto/signUp-user.dto';
|
|
import {
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
HttpCode,
|
|
Patch,
|
|
Post,
|
|
Req,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { AuthService } from './auth.service';
|
|
|
|
@Controller('auth')
|
|
export class AuthController {
|
|
constructor(private readonly authService: AuthService) {}
|
|
|
|
@Public()
|
|
@HttpCode(200)
|
|
@Post('sing-up')
|
|
// @ApiOperation({ summary: 'Create a new user' })
|
|
// @ApiResponse({ status: 201, description: 'User created successfully.' })
|
|
async singUp(@Body() payload: SingUpUserDto) {
|
|
const data = await this.authService.singUp(payload);
|
|
return { message: 'User created successfully', data };
|
|
// return { message: 'User created successfully', data };
|
|
}
|
|
|
|
@Public()
|
|
@HttpCode(200)
|
|
@Post('sign-in')
|
|
async signIn(@Body() signInUserDto: SignInUserDto) {
|
|
return await this.authService.signIn(signInUserDto);
|
|
}
|
|
|
|
@Post('sign-out')
|
|
//@RequirePermissions('auth:sign-out')
|
|
async signOut(@Body() signOutUserDto: SignOutUserDto) {
|
|
await this.authService.signOut(signOutUserDto);
|
|
return { message: 'User signed out successfully' };
|
|
}
|
|
|
|
// @Post('forgot-password')
|
|
// async forgotPassword(@Body() forgotPasswordDto: ForgotPasswordDto) {
|
|
// await this.authService.forgotPassword(forgotPasswordDto);
|
|
// return { message: 'Password reset link sent to your email' };
|
|
// }
|
|
|
|
// @UseGuards(JwtRefreshGuard)
|
|
@Public()
|
|
@HttpCode(200)
|
|
@Patch('refresh')
|
|
//@RequirePermissions('auth:refresh-token')
|
|
async refreshToken(@Body() refreshTokenDto: any) {
|
|
|
|
const data = await this.authService.refreshToken(refreshTokenDto);
|
|
|
|
if (!data) return null;
|
|
|
|
return {tokens: data}
|
|
}
|
|
|
|
// @Public()
|
|
// @HttpCode(200)
|
|
// @Get('test')
|
|
// async test() {
|
|
// return 'aplication test success';
|
|
// }
|
|
}
|