Skip to content

Commit

Permalink
feat: add full support for swagger (#12)
Browse files Browse the repository at this point in the history
* feat: add initial swagger docs

* feat: add swagger documentation

* fix(user): controller not using CurrentUser decorator
  • Loading branch information
CondensedMilk7 authored Sep 7, 2023
1 parent 50283b4 commit c88d1bb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
7 changes: 3 additions & 4 deletions nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"assets": [
"modules/mail/templates/**/*"
],
"assets": ["modules/mail/templates/**/*"],
"watchAssets": true,
"deleteOutDir": true
"deleteOutDir": true,
"plugins": ["@nestjs/swagger"]
}
}
9 changes: 7 additions & 2 deletions src/modules/user/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '@nestjs/common';
import { AuthService } from './auth.service';
import {
SignInDto,
SignUpDto,
UpdateUserDto,
UpdateUserPasswordDto,
Expand All @@ -36,8 +37,12 @@ export class AuthController {

@Post('sign_in')
@UseGuards(LocalAuthGuard)
signIn(@Request() req, @Res({ passthrough: true }) response: Response) {
return this.authService.signIn(req.user, response);
signIn(
@CurrentUser() user: UserPayload,
@Res({ passthrough: true }) response: Response,
@Body() dto: SignInDto,
) {
return this.authService.signIn(user, response);
}

@Get('test')
Expand Down
7 changes: 3 additions & 4 deletions src/modules/user/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ export class AuthService {
return null;
}

async signIn(user: UserInterface, response: Response) {
const payload = this.createPayload(user);
const accessToken = this.jwtService.sign(payload);
const refreshToken = this.jwtService.sign(payload, { expiresIn: '7d' });
async signIn(user: UserPayload, response: Response) {
const accessToken = this.jwtService.sign(user);
const refreshToken = this.jwtService.sign(user, { expiresIn: '7d' });
response.cookie('access_token', accessToken, {
expires: new Date(
Date.now() + Number(process.env.JWT_EXPIRES_IN) * 60 * 60 * 1000,
Expand Down

0 comments on commit c88d1bb

Please sign in to comment.