Skip to content

Commit

Permalink
Merge branch 'fix' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
sally0226 committed Aug 14, 2024
2 parents d92945e + 7bbffc7 commit 5ccf986
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
14 changes: 6 additions & 8 deletions src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Response } from 'express';

import { KakaoInfo } from 'src/common/decorators/kakao-info.decorator';
import { KakaoGuard } from 'src/common/guards/kakao.guard';
import { getCookieOption } from 'src/common/helper/cookie.helper';
import { UserProvider } from 'src/entities';

import { AuthService } from './auth.service';
Expand All @@ -32,14 +33,11 @@ export class AuthController {
kakaoRefreshToken: refreshToken,
});

res.cookie('Authorization', 'Bearer ' + user.accessToken, {
httpOnly: true,
sameSite: 'none',
secure: true,
path: '/',
expires: new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 1 * 365),
domain: '.korrk.kr',
});
res.cookie(
'Authorization',
'Bearer ' + user.accessToken,
getCookieOption(),
);

return res.redirect(302, this.configService.get('CLIENT_URL'));
}
Expand Down
9 changes: 7 additions & 2 deletions src/auth/strategies/jwt.strategy.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { Injectable, UnauthorizedException } from '@nestjs/common';
import {
Injectable,
NotFoundException,
UnauthorizedException,
} from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { PassportStrategy } from '@nestjs/passport';

import { ExtractJwt, Strategy, VerifiedCallback } from 'passport-jwt';

import { User } from 'src/entities/index';
import { UserService } from 'src/user/user.service';

@Injectable()
Expand All @@ -19,7 +24,7 @@ export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
}

async validate(payload: { id: number }, done: VerifiedCallback) {
const user = await this.userService.findOne({
const user: User = await this.userService.findOne({
id: payload.id,
});
if (!user) {
Expand Down
21 changes: 21 additions & 0 deletions src/common/helper/cookie.helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { CookieOptions } from 'express';

import { getNodeEnv } from 'src/common/helper/env.helper';
import { NODE_ENVIRONMENT } from 'src/common/helper/env.validation';

export const getCookieOption = (): CookieOptions => {
if (getNodeEnv === NODE_ENVIRONMENT.development) {
return {
path: '/',
maxAge: 360000,
};
}
return {
httpOnly: true,
sameSite: 'none',
secure: true,
path: '/',
expires: new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 1 * 365),
domain: '.korrk.kr',
};
};
2 changes: 1 addition & 1 deletion src/map/map.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class MapService {
async findAll(user: User): Promise<MapItemForUserDto[]> {
const userMapList = await this.userMapRepository.find(
{ user: user },
{ populate: ['map'] },
{ populate: ['map'], orderBy: { createdAt: 'DESC' } },
);

return userMapList.map(({ map, role }) => {
Expand Down

0 comments on commit 5ccf986

Please sign in to comment.