Skip to content
Snippets Groups Projects
Commit 73c06f81 authored by Wo-ogie's avatar Wo-ogie
Browse files

refactor: cookie-session 로그인 방식으로 수정

parent 159a6944
No related branches found
No related tags found
No related merge requests found
...@@ -57,33 +57,11 @@ async function validatePasswordIsMatched(requestPassword, exPassword) { ...@@ -57,33 +57,11 @@ async function validatePasswordIsMatched(requestPassword, exPassword) {
} }
} }
function setParticipantDataToCookie(req, res, participant) { function storeParticipantDataToSession(req, res, participant) {
const cookieName = 'participantData'; req.session.participant = {
const cookieOptions = {
httpOnly: true,
signed: true,
};
const existCookie = req.signedCookies.participantData || null;
if (existCookie) {
res.clearCookie(
cookieName,
JSON.stringify({
meetingId: existCookie.meetingId,
participantId: existCookie.participantId,
}),
cookieOptions,
);
}
res.cookie(
cookieName,
JSON.stringify({
meetingId: participant.MeetingId, meetingId: participant.MeetingId,
participantId: participant.id, participantId: participant.id,
}), };
cookieOptions,
);
} }
exports.createMeeting = async (req, res, next) => { exports.createMeeting = async (req, res, next) => {
...@@ -131,7 +109,7 @@ exports.entry = async (req, res, next) => { ...@@ -131,7 +109,7 @@ exports.entry = async (req, res, next) => {
participant.password, participant.password,
); );
} }
setParticipantDataToCookie(req, res, participant); storeParticipantDataToSession(req, res, participant);
return res.status(204).end(); return res.status(204).end();
} catch (error) { } catch (error) {
return next(error); return next(error);
......
function parseParticipantData(req, res, next) { function getParticipantDataFromSession(req, res, next) {
let participantData = null; const participantData = req.session.participant;
if (req.signedCookies.participantData) {
participantData = JSON.parse(req.signedCookies.participantData);
}
if (!participantData) { if (!participantData) {
const error = new Error('인증 권한이 없습니다.'); const error = new Error('인증 권한이 없습니다.');
error.status = 401; error.status = 401;
...@@ -12,7 +9,7 @@ function parseParticipantData(req, res, next) { ...@@ -12,7 +9,7 @@ function parseParticipantData(req, res, next) {
} }
exports.isAuthenticated = (req, res, next) => { exports.isAuthenticated = (req, res, next) => {
const participantData = parseParticipantData(req, res, next); const participantData = getParticipantDataFromSession(req, res, next);
if (participantData.meetingId !== req.params.meetingId) { if (participantData.meetingId !== req.params.meetingId) {
const error = new Error('접근 권한이 없습니다.'); const error = new Error('접근 권한이 없습니다.');
error.status = 401; error.status = 401;
...@@ -23,6 +20,6 @@ exports.isAuthenticated = (req, res, next) => { ...@@ -23,6 +20,6 @@ exports.isAuthenticated = (req, res, next) => {
}; };
exports.getLoggedInParticipantId = (req, res, next) => { exports.getLoggedInParticipantId = (req, res, next) => {
const participantData = parseParticipantData(req, res, next); const participantData = getParticipantDataFromSession(req, res, next);
return participantData?.participantId; return participantData?.participantId;
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment