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
e67e1bf4
Commit
e67e1bf4
authored
3 months ago
by
tpgus2603
Browse files
Options
Downloads
Patches
Plain Diff
refactor: 로그인 오류수정
parent
177fc754
No related branches found
Branches containing commit
No related tags found
1 merge request
!42
[#25] 배포코드 master브랜치로 이동
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
routes/auth.js
+11
-7
11 additions, 7 deletions
routes/auth.js
with
11 additions
and
7 deletions
routes/auth.js
+
11
−
7
View file @
e67e1bf4
// routes/auth.js
const
express
=
require
(
'
express
'
);
const
passport
=
require
(
'
passport
'
);
...
...
@@ -15,17 +14,20 @@ router.get('/logout', (req, res) => {
if
(
err
)
{
return
res
.
status
(
500
).
json
({
error
:
'
Failed to logout
'
});
}
res
.
redirect
(
process
.
env
.
FRONTEND_URL
);
res
.
redirect
(
process
.
env
.
FRONTEND_URL
||
'
http://localhost:3000
'
);
// 기본값 설정
});
});
// GET /auth/google
router
.
get
(
'
/google
'
,
(
req
,
res
,
next
)
=>
{
const
redirectUrl
=
req
.
query
.
redirectUrl
||
process
.
env
.
FRONTEND_URL
;
// 기본 redirectUrl 설정
const
redirectUrl
=
req
.
query
.
redirectUrl
||
process
.
env
.
FRONTEND_URL
||
'
http://localhost:3000
'
;
// 리다이렉트 URL 검증
const
allowedDomains
=
[
process
.
env
.
FRONTEND_URL
];
if
(
!
allowedDomains
.
some
((
domain
)
=>
redirectUrl
.
startsWith
(
domain
)))
{
// allowedDomains 배열 확인 및 기본값 설정
const
allowedDomains
=
[
process
.
env
.
FRONTEND_URL
||
'
http://localhost:3000
'
];
// redirectUrl 검증
if
(
!
allowedDomains
.
some
((
domain
)
=>
redirectUrl
&&
redirectUrl
.
startsWith
(
domain
)))
{
return
res
.
status
(
400
).
json
({
error
:
'
Invalid redirect URL
'
});
}
...
...
@@ -41,10 +43,12 @@ router.get(
passport
.
authenticate
(
'
google
'
,
{
failureRedirect
:
'
/auth/login
'
}),
(
req
,
res
)
=>
{
// 세션에서 redirectUrl 가져오기
const
redirectUrl
=
req
.
session
.
redirectUrl
||
process
.
env
.
FRONTEND_URL
;
const
redirectUrl
=
req
.
session
.
redirectUrl
||
process
.
env
.
FRONTEND_URL
||
'
http://localhost:3000
'
;
// 세션에서 redirectUrl 제거
req
.
session
.
redirectUrl
=
null
;
// 프론트엔드로 리다이렉트
res
.
redirect
(
redirectUrl
);
}
);
...
...
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