Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WebBack
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
websystem
WebBack
Commits
95f8e123
Commit
95f8e123
authored
4 months ago
by
tpgus2603
Browse files
Options
Downloads
Patches
Plain Diff
refactor: 로컬테스트용 로그인로직 수정
parent
39c45e32
Branches
Branches containing commit
No related tags found
1 merge request
!42
[#25] 배포코드 master브랜치로 이동
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
app.js
+1
-1
1 addition, 1 deletion
app.js
middlewares/auth.js
+7
-6
7 additions, 6 deletions
middlewares/auth.js
passport/googleStrategy.js
+4
-4
4 additions, 4 deletions
passport/googleStrategy.js
routes/auth.js
+1
-2
1 addition, 2 deletions
routes/auth.js
routes/session.js
+26
-0
26 additions, 0 deletions
routes/session.js
with
39 additions
and
13 deletions
app.js
+
1
−
1
View file @
95f8e123
...
...
@@ -55,7 +55,7 @@ app.use(passport.session());
app
.
use
(
flash
());
app
.
set
(
'
trust proxy
'
,
1
);
//
app.set('trust proxy', 1);
console
.
log
(
'
MongoDB URI:
'
,
process
.
env
.
MONGO_URI
);
//라우터 등록
const
authRoutes
=
require
(
'
./routes/auth
'
);
...
...
This diff is collapsed.
Click to expand it.
middlewares/auth.js
+
7
−
6
View file @
95f8e123
// middlewares/auth.js
exports
.
isLoggedIn
=
(
req
,
res
,
next
)
=>
{
//로그인된 사용자자만 접근허용
exports
.
isLoggedIn
=
(
req
,
res
,
next
)
=>
{
// 로그인된 사용자만 접근 허용
if
(
req
.
isAuthenticated
())
{
return
next
();
}
res
.
redirect
(
'
/auth/login
'
);
// 리다이렉트 대신 401 Unauthorized 상태 반환
res
.
status
(
401
).
json
({
error
:
'
로그인 되지않은 사용자
'
});
};
exports
.
isNotLoggedIn
=
(
req
,
res
,
next
)
=>
{
//로그인 안
되면 리다이렉트
exports
.
isNotLoggedIn
=
(
req
,
res
,
next
)
=>
{
//
로그인 안
된 사용자만 접근 허용
if
(
!
req
.
isAuthenticated
())
{
return
next
();
}
res
.
redirect
(
'
/
'
);
};
// 리다이렉트 대신 400 Bad Request 상태 반환 (필요에 따라 변경 가능)
res
.
status
(
400
).
json
({
error
:
'
이미 로그인된
'
});
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
passport/googleStrategy.js
+
4
−
4
View file @
95f8e123
// passport/googleStrategy.js
const
{
Strategy
:
GoogleStrategy
}
=
require
(
'
passport-google-oauth20
'
);
const
User
=
require
(
'
../models/user
'
);
const
User
=
require
(
'
../models/user
'
);
module
.
exports
=
new
GoogleStrategy
(
{
clientID
:
process
.
env
.
GOOGLE_CLIENT_ID
,
clientSecret
:
process
.
env
.
GOOGLE_CLIENT_SECRET
,
callbackURL
:
process
.
env
.
CALLBACK_URL
,
passReqToCallback
:
true
,
// req 객체를 콜백에 전달
},
async
(
accessToken
,
refreshToken
,
profile
,
done
)
=>
{
async
(
req
,
accessToken
,
refreshToken
,
profile
,
done
)
=>
{
try
{
// 프로필에서 사용자 정보 추출
const
email
=
profile
.
emails
[
0
].
value
;
...
...
@@ -23,7 +23,7 @@ module.exports = new GoogleStrategy(
return
done
(
null
,
user
);
}
catch
(
err
)
{
return
done
(
err
);
return
done
(
err
,
null
);
}
}
);
This diff is collapsed.
Click to expand it.
routes/auth.js
+
1
−
2
View file @
95f8e123
...
...
@@ -12,11 +12,10 @@ router.get(
})
);
// Google OAuth 콜백 라우터
router
.
get
(
'
/google/callback
'
,
passport
.
authenticate
(
'
google
'
,
{
failureRedirect
:
'
/auth/login
'
failureRedirect
:
`
${
process
.
env
.
FRONT_URL
}
/login`
// 수정된 부분
}),
(
req
,
res
)
=>
{
const
redirectUrl
=
process
.
env
.
FRONT_URL
;
...
...
This diff is collapsed.
Click to expand it.
routes/session.js
0 → 100644
+
26
−
0
View file @
95f8e123
const
express
=
require
(
'
express
'
);
const
router
=
express
.
Router
();
// GET /api/session/info
router
.
get
(
'
/info
'
,
(
req
,
res
)
=>
{
if
(
req
.
user
)
{
const
{
email
,
name
}
=
req
.
user
;
// 캐싱 비활성화
res
.
set
(
'
Cache-Control
'
,
'
no-store
'
);
res
.
set
(
'
Pragma
'
,
'
no-cache
'
);
return
res
.
status
(
200
).
json
({
user
:
{
email
,
name
,
},
});
}
// 세션이 만료되었거나 사용자 정보가 없는 경우
res
.
set
(
'
Cache-Control
'
,
'
no-store
'
);
res
.
set
(
'
Pragma
'
,
'
no-cache
'
);
res
.
status
(
401
).
json
({
message
:
'
세션이 만료되었거나 사용자 정보가 없습니다.
'
,
});
});
module
.
exports
=
router
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment