-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
사용자 인증절차 강화 #47
Open
Ryu-02
wants to merge
2
commits into
develop
Choose a base branch
from
feat/#44/profile_crud
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
사용자 인증절차 강화 #47
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
"use strict"; | ||
|
||
module.exports = function isAuthenticated(req, res, next) { | ||
if (req.session && req.session.user) { | ||
// 세션이 존재하고 사용자 정보가 있으면 인증된 것으로 간주 | ||
next(); | ||
} else { | ||
// 인증되지 않은 경우 | ||
res.status(401).json({ message: "인증이 필요합니다." }); | ||
const userStorage = require("../storages/userStorage"); | ||
|
||
module.exports = async function isAuthenticated(req, res, next) { | ||
try { | ||
console.log(req.sessionID); | ||
if (req.session && req.session.user) { | ||
// 세션 ID를 사용하여 DB에서 세션 정보 조회 | ||
const isSessionValid = await userStorage.getSessionInfo(req.sessionID); | ||
|
||
if (isSessionValid) { | ||
// 세션이 유효하면 인증된 것으로 간주 | ||
next(); | ||
} else { | ||
// 세션 정보가 없으면 인증되지 않은 것으로 간주 | ||
res.status(401).json({ message: "로그인이 필요합니다." }); | ||
} | ||
} else { | ||
// 세션이 없거나 사용자 정보가 없으면 인증되지 않은 것으로 간주 | ||
res.status(401).json({ message: "로그인이 필요합니다." }); | ||
} | ||
} catch (error) { | ||
console.error("인증 중 오류:", error); | ||
res.status(500).json({ message: "서버 오류" }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
엇 sessions 테이블을 새로 만드신건가요??
찾아보니까 명규님이 말씀하신대로 DB에 세션 정보 저장을 안해도 된다고 봐서요 !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
session 테이블은 mysql-session 사용을 하면 자동으로 테이블이 생성되고, app.js에서 설정한 대로 db에 자동으로 들어가고 만료되면 사라지는 구조로 자동 생성 되는걸로 알고있습니다 !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
와우 그런 구조가 ... 신기하네요 !!
알겠습니다 ~