Skip to content

Commit

Permalink
feat: 구 세션 재발급
Browse files Browse the repository at this point in the history
  • Loading branch information
LuizyHub committed Dec 7, 2023
1 parent 8661b2d commit 1f07b43
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion packages/backend/src/quizzes/quizzes.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,18 @@ export class QuizzesController {
@Res() response: Response,
@SessionId() sessionId: string,
): Promise<CommandResponseDto> {
await this.sessionService.checkLogLength(sessionId, id);
try {
await this.sessionService.checkLogLength(sessionId, id);
} catch (e) {
this.logger.log('info', 'session not found. creating session..');
response.cookie(
'sessionId',
(sessionId = await this.sessionService.createSession()),
{
httpOnly: true,
},
); // 세션 아이디를 생성한다.
}
try {
if (!sessionId) {
// 세션 아이디가 없다면
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/session/session-save.intercepter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class SessionUpdateInterceptor implements NestInterceptor {
return next.handle().pipe(
tap(() => {
sessionId =
sessionId || this.extractSessionId(response.getHeader('Set-Cookie')); // 세션 ID가 없으면 쿠키에서 추출
this.extractSessionId(response.getHeader('Set-Cookie')) || sessionId; // 세션 ID가 없으면 쿠키에서 추출
// 세션 업데이트 로직
this.sessionService.saveSession(sessionId);
}),
Expand Down

0 comments on commit 1f07b43

Please sign in to comment.