로딩...

firebase

  • firebase 프로젝트를 등록하면 google cloud console 에 firebase 가 테스트 사용 및 API 키를 자동으로 등록한다
  • firebase 프로젝트를 등록하면 google cloud console 에 firebase 서비스계정을 자동으로 등록한다

flowchart

flowchart
  ad[developer.apple.com] -.key includes APNs: push..-> f
  ad[developer.apple.com] -.appstore id, bundle id, team_id..-> f
  gc[console.cloud.google.com] -.CLIENT_ID: oauth.-> f
  f[console.firebase.google.com] --GoogleService-info.plist--> i[ios app]
  f[console.firebase.google.com] --google-services.json--> i[android app]

client

  • console.firebase.google.com 에서 각 플랫폼별 google-services.json 을 다운받는다
  • 문서가 두개가 있는데 firebase 문서가 아닌 rnfirebase.io Getting Started 문서를 따라간다
  • android
    • android/appgoogle-services.json 복사
    • android/build.grade dependecies 에 classpath 'com.google.com:google-service:4.3.15' 추가한다
      • google sigin 관련 라이브러 설치하면서 이미 설정되어있음
    • android/app/build.grade 에서 apply plugin
  • ios
    • console.firebase.google.com 에서 ios 앱도 프로젝트 설정을 해주어야한다
      • 주의 앱 번들 ID는 변경불가
    • 개발자 등록후 진행
    • 패키지 설치
      • spm 을 사용하는 방법도 있으나 결과적으로 실패
      • pod 에서와 같이 수정하고 flipper 를 주석 처리하는 방법이 적혀있으나 안됨
        # right after `use_frameworks! :linkage => :static`
        $RNFirebaseAsStaticFramework = true
        
      • ios/Podfile 에 추가하는 것으로 해결
        pod 'FirebaseCore', :modular_headers => true
        
    • AppDelegate.mm 수정

serverside

error

Error: No Firebase App '[DEFAULT]' has been created - call firebase.initializeApp()

Error: No Firebase App '[DEFAULT]' has been created - call firebase.initializeApp()
  • android 에서 발생했으며 설정이슈 [[#client]] 설정 참고

TypeError: Cannot read properties of undefined (reading 'INTERNAL')

TypeError: Cannot read properties of undefined (reading 'INTERNAL')
    at initializeApp (.yarn/cache/firebase-admin-npm-12.0.0-a20a06d34c-70e619250d.zip/node_modules/firebase-admin/lib/app/firebase-namespace.js:246:21)
import { initializeApp, credential } from 'firebase-admin'
import { applicationDefault } from 'firebase-admin/app'

const app = initializeApp({
  credential: applicationDefault()
})
  • to-be
import admin from 'firebase-admin'
import { applicationDefault } from 'firebase-admin/app'

const app = admin.initializeApp({
  credential: applicationDefault()
})

The default Firebase app already exists. This means you called initializeApp() more than once without providing an app name as the second argument. In most cases you only need to call initializeApp() once. But if you do want to initialize multiple apps, pass a second argument to initializeApp() to give each app a unique name.

  errorInfo: {
    code: 'app/duplicate-app',
    message: 'The default Firebase app already exists. This means you called initializeApp() more than once without providing an app name as the second argument. In most cases you only need to call initializeApp() once. But if you do want to initialize multiple apps, pass a second argument to initializeApp() to give each app a unique name.'
  },
  codePrefix: 'app',
  page: '/api/test/fcm'
import admin from 'firebase-admin'
import { applicationDefault, getApp, getApps } from 'firebase-admin/app'

const apps = getApps()
const app = apps[0] ?? admin.initializeApp({
  credential: applicationDefault()
})