Skip to content

Commit

Permalink
hotfix: 세션 쿠키를 기한을 30분으로 설정한 persist 쿠키로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
dooohun committed Dec 4, 2024
1 parent 32c951f commit dd9535b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/client/src/pages/nickname/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function Nickname() {
navigate(`/`);
return;
}
setCookie('sid', sid);
setCookie('sid', sid, 30);
socket.emit('participant notice', { pinCode: pinCode });
navigate(`/quiz/wait/${pinCode}`);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/pages/quiz-list/ui/ClassItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function ClassItem({ index, quizList }: ClassItemProps) {
socket.emit('master entry', { classId: id });

const sid = await waitForSocketEvent('session', socket);
setCookie('sid', sid);
setCookie('sid', sid, 30);

const pinCode = await waitForSocketEvent('pincode', socket);

Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/shared/hooks/useSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const useSocket = () => {

if (!sid) {
socketRef.current.on('session', (sid: string) => {
setCookie('sid', sid);
setCookie('sid', sid, 30);
});
}

Expand Down
8 changes: 4 additions & 4 deletions packages/client/src/shared/utils/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export function getCookie(name: string) {
return undefined;
}

export function setCookie(name: string, val: any, day?: number) {
export function setCookie(name: string, val: any, minute?: number) {
const date = new Date();
const value = val;
// day가 없는 경우 세션쿠키로 설정
if (day) {
date.setTime(date.getTime() + day * 24 * 60 * 60 * 1000);
// minute가 없는 경우 세션쿠키로 설정
if (minute) {
date.setTime(date.getTime() + minute * 60 * 1000);
document.cookie = `${name}=${value}; expires=${date.toUTCString()}; path=/`;
} else {
document.cookie = `${name}=${value}; path=/`;
Expand Down

0 comments on commit dd9535b

Please sign in to comment.