Skip to content

Commit

Permalink
Apply lint
Browse files Browse the repository at this point in the history
  • Loading branch information
xet-a committed Aug 25, 2024
1 parent 1a657bb commit a2a80ab
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
13 changes: 11 additions & 2 deletions backend/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { Body, Controller, Get, HttpRedirectResponse, Post, Redirect, Req, UseGuards } from "@nestjs/common";
import {
Body,
Controller,
Get,
HttpRedirectResponse,
Post,
Redirect,
Req,
UseGuards,
} from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { AuthGuard } from "@nestjs/passport";
import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
Expand Down Expand Up @@ -38,7 +47,7 @@ export class AuthController {
@Public()
@Post("refresh")
@UseGuards(AuthGuard("refresh"))
@ApiOperation({ summary: 'Refresh Access Token' })
@ApiOperation({ summary: "Refresh Access Token" })
@ApiResponse({ type: LoginResponse })
async refresh(@Body() body: RefreshTokenRequest): Promise<{ accessToken: string }> {
const accessToken = await this.authService.getNewAccessToken(body.refreshToken);
Expand Down
4 changes: 1 addition & 3 deletions backend/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import { JwtStrategy } from "./jwt.strategy";
return {
global: true,
signOptions: {
expiresIn: `${configService.get(
'JWT_ACCESS_TOKEN_EXPIRATION_TIME',
)}s`,
expiresIn: `${configService.get("JWT_ACCESS_TOKEN_EXPIRATION_TIME")}s`,
},
secret: configService.get<string>("JWT_ACCESS_TOKEN_SECRET"),
};
Expand Down
20 changes: 7 additions & 13 deletions backend/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from "@nestjs/common";
import { ConfigService } from '@nestjs/config';
import { ConfigService } from "@nestjs/config";
import { JwtService } from "@nestjs/jwt";
import { UsersService } from "src/users/users.service";
import { LoginRequest } from "./types/login-request.type";
Expand All @@ -16,36 +16,30 @@ export class AuthService {
async loginWithGithub(req: LoginRequest): Promise<LoginResponse> {
const user = await this.usersService.findOrCreate(
req.user.socialProvider,
req.user.socialUid,
req.user.socialUid
);

const accessToken = this.jwtService.sign(
{ sub: user.id, nickname: user.nickname },
{ expiresIn: `${this.configService.get(
'JWT_ACCESS_TOKEN_EXPIRATION_TIME',
)}s`, },
{ expiresIn: `${this.configService.get("JWT_ACCESS_TOKEN_EXPIRATION_TIME")}s` }
);

const refreshToken = this.jwtService.sign(
{ sub: user.id },
{ expiresIn: `${this.configService.get(
'JWT_REFRESH_TOKEN_EXPIRATION_TIME',
)}s`, },
{ expiresIn: `${this.configService.get("JWT_REFRESH_TOKEN_EXPIRATION_TIME")}s` }
);

return {accessToken, refreshToken};
return { accessToken, refreshToken };
}

async getNewAccessToken(refreshToken: string) {
const payload = this.jwtService.verify(refreshToken);

const newAccessToken = this.jwtService.sign(
{ sub: payload.sub, nickname: payload.nickname },
{ expiresIn: `${this.configService.get(
'JWT_ACCESS_TOKEN_EXPIRATION_TIME',
)}s`, },
{ expiresIn: `${this.configService.get("JWT_ACCESS_TOKEN_EXPIRATION_TIME")}s` }
);

return newAccessToken;
}
}
}
4 changes: 1 addition & 3 deletions backend/src/auth/jwt.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { JwtPayload } from "src/utils/types/jwt.type";
import { AuthorizedUser } from "src/utils/types/req.type";

@Injectable()
export class JwtStrategy extends PassportStrategy(
PassportJwtStrategy, "jwt"
) {
export class JwtStrategy extends PassportStrategy(PassportJwtStrategy, "jwt") {
constructor(configService: ConfigService) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
Expand Down
8 changes: 4 additions & 4 deletions backend/src/auth/types/refresh-token-request.type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IsString } from 'class-validator';
import { IsString } from "class-validator";

export class RefreshTokenRequest {
@IsString()
refreshToken: string;
}
@IsString()
refreshToken: string;
}

0 comments on commit a2a80ab

Please sign in to comment.