-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feat/#104 | 메인페이지, 리딩스페이스 수정 및 타유저페이지 1차
- Loading branch information
Showing
55 changed files
with
2,390 additions
and
546 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
importScripts( | ||
"https://www.gstatic.com/firebasejs/9.20.0/firebase-app-compat.js" | ||
); | ||
importScripts( | ||
"https://www.gstatic.com/firebasejs/9.20.0/firebase-messaging-compat.js" | ||
); | ||
|
||
// Firebase 초기화 | ||
const firebaseConfig = { | ||
apiKey: "AIzaSyDobXyNl2FmQpOJTcdu0cU6lIw6jZ4V4Dw", | ||
authDomain: "bookduck-3654b.firebaseapp.com", | ||
projectId: "bookduck-3654b", | ||
storageBucket: "bookduck-3654b.firebasestorage.app", | ||
messagingSenderId: "259472501168", | ||
appId: "1:259472501168:web:f0ce654387126e1f458e75", | ||
measurementId: "G-XNN57JYCHJ", | ||
}; | ||
firebase.initializeApp(firebaseConfig); | ||
|
||
const messaging = firebase.messaging(); | ||
|
||
messaging.onBackgroundMessage((payload) => { | ||
console.log("백그라운드 메시지 수신:", payload); | ||
|
||
const notificationTitle = payload.notification.title || "알림 제목 없음"; | ||
const notificationOptions = { | ||
body: payload.notification.body || "알림 내용 없음", | ||
}; | ||
|
||
self.registration.showNotification(notificationTitle, notificationOptions); | ||
}); | ||
|
||
self.addEventListener("install", (event) => { | ||
console.log("Service Worker 설치됨"); | ||
self.skipWaiting(); // 새 Service Worker를 즉시 활성화 | ||
}); | ||
|
||
self.addEventListener("activate", (event) => { | ||
console.log("Service Worker 활성화됨"); | ||
return self.clients.claim(); // 기존 클라이언트 제어 | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { getToken } from "firebase/messaging"; | ||
import { messaging } from "./firebase"; | ||
|
||
export const requestFcmToken = async () => { | ||
try { | ||
// 서비스 워커 등록 | ||
if ("serviceWorker" in navigator) { | ||
const registration = await navigator.serviceWorker.register( | ||
"/firebase-messaging-sw.js" | ||
); | ||
console.log("서비스 워커 등록 성공:", registration); | ||
|
||
// FCM 토큰 가져오기 | ||
const fcmToken = await getToken(messaging, { | ||
vapidKey: | ||
"BNgk_Ef8j0KFLabeiH5K7GGsHz4BC00C05R3hzNA20CXGQ7YCCfCe0fx9FCHSdhlRj6DNlC90IrCqBiQW8_6KKw", // Firebase 콘솔에서 발급받은 VAPID 키 | ||
serviceWorkerRegistration: registration, | ||
}); | ||
|
||
if (fcmToken) { | ||
console.log("FCM 토큰:", fcmToken); | ||
return fcmToken; | ||
} else { | ||
console.error("FCM 토큰을 가져오지 못했습니다."); | ||
return null; | ||
} | ||
} else { | ||
console.error("Service Worker가 지원되지 않는 환경입니다."); | ||
return null; | ||
} | ||
} catch (error) { | ||
console.error("FCM 토큰 요청 중 오류 발생:", error); | ||
return null; | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { post } from "./example"; | ||
export const sendFcmToken = async (userId, fcmToken) => { | ||
try { | ||
// POST 요청으로 FCM 토큰 전송 | ||
const response = await post(`/fcm/${userId}/token`, { fcmToken }); | ||
console.log("FCM 토큰 전송 성공:", response); | ||
return response; | ||
} catch (error) { | ||
console.error("FCM 토큰 전송 실패:", error); | ||
throw error; | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { initializeApp } from "firebase/app"; | ||
import { getMessaging } from "firebase/messaging"; | ||
|
||
const firebaseConfig = { | ||
apiKey: "AIzaSyDobXyNl2FmQpOJTcdu0cU6lIw6jZ4V4Dw", | ||
authDomain: "bookduck-3654b.firebaseapp.com", | ||
projectId: "bookduck-3654b", | ||
storageBucket: "bookduck-3654b.firebasestorage.app", | ||
messagingSenderId: "259472501168", | ||
appId: "1:259472501168:web:f0ce654387126e1f458e75", | ||
measurementId: "G-XNN57JYCHJ", | ||
}; | ||
|
||
// Initialize Firebase | ||
const app = initializeApp(firebaseConfig); | ||
const messaging = getMessaging(app); | ||
|
||
export { messaging }; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.