inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

React에서 FCM 사용

1109

김민지

작성한 질문수 1

0

안녕하세요 !

FCM으로 푸시 기능을 짜다가,, 도저히 모르겠어서 글 남깁니다 ..!

 

문제는 콘솔에는 푸시 알림이 왔다는 게 찍히는데,

푸시가 보이지 않습니다 ... ㅠㅠ

[ 폴더 구조 ]

[ firebase-messaging-sw.js ]

self.addEventListener('push', function (e) {
  console.log('push: ', e.data.json())
  if (!e.data.json()) return

  const resultData = e.data.json().notification
  const notificationTitle = resultData.title
  const notificationOptions = {
    body: resultData.body,
    icon: resultData.image,
    tag: resultData.tag,
    ...resultData
  }
  console.log('push: ', { resultData, notificationTitle, notificationOptions })

  registration.showNotification(notificationTitle, notificationOptions)
})

[ messaging_init_in_sw.js ]

import { initializeApp } from 'firebase/app'
import { getMessaging, getToken } from 'firebase/messaging'

const firebaseConfig = {
  apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
  authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
  projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
  storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
  messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_ID,
  appId: process.env.REACT_APP_FIREBASE_APP_ID,
  measurementId: process.env.REACT_APP_FIREBASE_MEASUREMENT_ID
}

function requestPermission() {
  console.log('푸시 허가 받는 중 ...')

  void Notification.requestPermission().then((permission) => {
    if (permission === 'granted') {
      console.log('푸시 알림이 허용되었습니다.')
    } else {
      console.log('푸시 알림이 허용되지 않았습니다')
    }
  })

  const app = initializeApp(firebaseConfig)
  const messaging = getMessaging(app)

  void getToken(messaging, { vapidKey: process.env.REACT_APP_FIREBASE_VAPID_KEY }).then((token) => {
    if (token.length > 0) {
      console.log('푸시 토큰 : ', token)
    } else {
      console.log('푸시 토큰 실패 !')
    }
  })
}

requestPermission()

 

토큰은 제대로 잘 받아와지는데,,, 혹시 서비스워커 코드에 문제가 있는 걸까요 ..?

react fcm firebase push

답변 1

0

김민지

image

혹시 localhost에서는 불가능한건가요 ..?!

이해가 절반 정도 되는데요.

0

3

0

bash 명령어가 너무 많아요..

0

15

1

createPointTransactionOfLoading 에러

0

8

1

cursor화면이 좀 달라요 ㅜ

0

14

1

93~94강. 서브에이전트와 Shrimp Task Manager Plan과 차이

0

14

0

power shell에서는 claude가 정상 실행되는데, cursor terminal에서는 실행 에러 발생하네요.

0

16

1

live server, korean도 확장팩 검색이 되지 않습니다.

0

17

0

CLAUDE.local.md

0

15

1

55강 관련 질문(커밋이 완료되지 않을 때)

0

17

1

클로드 코드를 쓸때 Cursor IDE의 이점?

0

23

1

오류사항

0

31

3

md 파일을 위한 폴더 관리의 기준이 궁금합니다.

0

21

2

혹시 결제연동

0

25

1

claude code가 작업중일때 ctrl t 눌러서 진행상황 확인 불가

0

25

1

메타프롬프트 관련

0

27

2

side bar positon. 어떻게 해도 안돼요..;

0

22

1

모델 고정방법 문의

0

21

2

98강. 1인 사이드프로젝트 시 질문

0

34

2

state 객체로 묶기

0

19

0

강의화면과 Cursor프로그램 화면이 달라서요..

0

27

2

커서 설치했는데 이해 안되네요

0

35

2

공식사이트 관련과 workspace

0

24

2

수업 잘 들었습니다.

2

25

2

user-memory-setup 저장 관련

0

23

2