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
005228ca
Commit
005228ca
authored
3 months ago
by
심재엽
Browse files
Options
Downloads
Patches
Plain Diff
refactor: fcmToken 등록 로직 수정
parent
0ab72462
No related branches found
Branches containing commit
No related tags found
2 merge requests
!42
[#25] 배포코드 master브랜치로 이동
,
!41
[#25] fcmToken 등록 로직 수정
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
routes/authRoute.js
+69
-44
69 additions, 44 deletions
routes/authRoute.js
routes/chatRoute.js
+4
-0
4 additions, 0 deletions
routes/chatRoute.js
services/memberService.js
+1
-1
1 addition, 1 deletion
services/memberService.js
with
74 additions
and
45 deletions
routes/authRoute.js
+
69
−
44
View file @
005228ca
const
express
=
require
(
'
express
'
);
const
passport
=
require
(
'
passport
'
);
const
express
=
require
(
'
express
'
);
const
passport
=
require
(
'
passport
'
);
const
MemberService
=
require
(
'
../services/memberService
'
);
const
router
=
express
.
Router
();
const
router
=
express
.
Router
();
// Google OAuth 로그인 라우터
router
.
get
(
'
/login
'
,
passport
.
authenticate
(
'
google
'
,
{
scope
:
[
'
profile
'
,
'
email
'
],
// 사용자 정보 요청을 위한 scope
failureRedirect
:
`
${
process
.
env
.
FRONT_URL
}
/login`
})
);
// Google OAuth 로그인 라우터
router
.
get
(
'
/login
'
,
(
req
,
res
,
next
)
=>
{
const
{
state
}
=
req
.
query
;
// 클라이언트에서 전달된 state(fcmToken)
console
.
log
(
"
State received at /login:
"
,
state
);
router
.
get
(
'
/google/callback
'
,
passport
.
authenticate
(
'
google
'
,
{
failureRedirect
:
`
${
process
.
env
.
FRONT_URL
}
/login`
}),
(
req
,
res
)
=>
{
const
redirectUrl
=
process
.
env
.
FRONT_URL
;
req
.
session
.
save
((
err
)
=>
{
if
(
err
)
{
console
.
error
(
'
세션 저장 오류:
'
,
err
);
return
res
.
status
(
500
).
json
({
error
:
'
서버 오류
'
});
}
res
.
redirect
(
redirectUrl
);
});
passport
.
authenticate
(
"
google
"
,
{
scope
:
[
"
profile
"
,
"
email
"
],
// 요청할 사용자 정보
state
,
// 전달받은 fcmToken을 state로 설정
})(
req
,
res
,
next
);
}
);
router
.
get
(
'
/google/callback
'
,
passport
.
authenticate
(
'
google
'
,
{
failureRedirect
:
`
${
process
.
env
.
FRONT_URL
}
/login`
}),
async
(
req
,
res
)
=>
{
// Google OAuth 인증 성공 후 state 파라미터로 전달된 fcmToken 가져오기
const
fcmToken
=
req
.
query
.
state
;
console
.
log
(
"
받아온 fcmToken
"
,
fcmToken
);
const
userEmail
=
req
.
user
.
email
;
// Google 로그인에서 가져온 email
const
redirectUrl
=
process
.
env
.
FRONT_URL
;
req
.
session
.
userEmail
=
userEmail
;
// 세션에 사용자 이메일 저장
try
{
if
(
fcmToken
)
{
// FCM 토큰 등록
await
MemberService
.
registerToken
(
userEmail
,
fcmToken
);
console
.
log
(
`FCM token registered for user:
${
userEmail
}
`
);
}
else
{
console
.
warn
(
"
No FCM token provided during login
"
);
}
}
catch
(
error
)
{
console
.
error
(
"
Error registering FCM token during login:
"
,
error
);
}
);
// 로그아웃 라우터
router
.
get
(
'
/logout
'
,
(
req
,
res
)
=>
{
if
(
req
.
session
)
{
req
.
session
.
destroy
((
err
)
=>
{
if
(
err
)
{
console
.
error
(
'
세션 삭제 오류:
'
,
err
);
return
res
.
status
(
500
).
json
({
error
:
'
서버 오류
'
});
}
const
redirectUrl
=
process
.
env
.
FRONT_URL
;
res
.
redirect
(
redirectUrl
);
});
}
else
{
// 세션이 없는 경우에도 리다이렉트
req
.
session
.
save
((
err
)
=>
{
if
(
err
)
{
console
.
error
(
'
세션 저장 오류:
'
,
err
);
return
res
.
status
(
500
).
json
({
error
:
'
서버 오류
'
});
}
res
.
redirect
(
redirectUrl
);
});
}
);
// 로그아웃 라우터
router
.
get
(
'
/logout
'
,
(
req
,
res
)
=>
{
if
(
req
.
session
)
{
req
.
session
.
destroy
((
err
)
=>
{
if
(
err
)
{
console
.
error
(
'
세션 삭제 오류:
'
,
err
);
return
res
.
status
(
500
).
json
({
error
:
'
서버 오류
'
});
}
const
redirectUrl
=
process
.
env
.
FRONT_URL
;
res
.
redirect
(
redirectUrl
);
}
});
// 사용자 삭제 라우터
});
}
else
{
// 세션이 없는 경우에도 리다이렉트
const
redirectUrl
=
process
.
env
.
FRONT_URL
;
res
.
redirect
(
redirectUrl
);
}
});
// 사용자 삭제 라우터
router
.
delete
(
'
/leave
'
,
async
(
req
,
res
)
=>
{
try
{
// 인증된 사용자 확인
...
...
@@ -81,4 +106,4 @@ router.delete('/leave', async (req, res) => {
}
});
module
.
exports
=
router
;
\ No newline at end of file
module
.
exports
=
router
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
routes/chatRoute.js
+
4
−
0
View file @
005228ca
const
express
=
require
(
'
express
'
);
const
router
=
express
.
Router
();
const
chatController
=
require
(
'
../controllers/chatController
'
);
const
{
isLoggedIn
}
=
require
(
'
../middlewares/auth
'
);
router
.
post
(
'
/create-room
'
,
chatController
.
createChatRoom
);
router
.
get
(
'
/rooms
'
,
chatController
.
getChatRooms
);
...
...
@@ -10,6 +11,9 @@ router.get('/unread-messages/:nickname', chatController.getUnreadMessages);
router
.
get
(
'
/unread-count/:chatRoomId
'
,
chatController
.
getUnreadCount
);
router
.
post
(
'
/update-status-and-logid
'
,
chatController
.
updateStatusAndLogId
);
router
.
post
(
'
/update-read-log-id
'
,
chatController
.
updateReadLogId
);
router
.
use
(
isLoggedIn
);
router
.
post
(
'
/:chatRoomId/notices
'
,
chatController
.
addNotice
);
router
.
get
(
'
/:chatRoomId/notices/latest
'
,
chatController
.
getLatestNotice
);
router
.
get
(
'
/:chatRoomId/notices
'
,
chatController
.
getAllNotices
);
...
...
This diff is collapsed.
Click to expand it.
services/memberService.js
+
1
−
1
View file @
005228ca
...
...
@@ -25,7 +25,7 @@ class MemberService {
}
// 3. MongoDB에서 관련 채팅방의 FCM 토큰 업데이트
const
existingChatRooms
=
await
ChatRoom
.
find
({
"
participants.name
"
:
user
.
name
});
const
existingChatRooms
=
await
ChatRoom
s
.
find
({
"
participants.name
"
:
user
.
name
});
for
(
const
room
of
existingChatRooms
)
{
room
.
participants
=
room
.
participants
.
map
((
participant
)
=>
{
if
(
participant
.
name
===
user
.
name
)
{
...
...
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