ES6 import에서 Firebase Admin, Cloud Storage 작성

자바 스크립트 -> TypeScript로 변환하는 동안 좀처럼 발견되지 않았기 때문에 메모가 나왔습니다
import * as admin from 'firebase-admin';
import * as serviceAccount from './serviceAccountKey.json';
import { Storage } from '@google-cloud/storage';

const params = {
  type: serviceAccount.type,
  projectId: serviceAccount.project_id,
  privateKeyId: serviceAccount.private_key_id,
  privateKey: serviceAccount.private_key,
  clientEmail: serviceAccount.client_email,
  clientId: serviceAccount.client_id,
  authUri: serviceAccount.auth_uri,
  tokenUri: serviceAccount.token_uri,
  authProviderX509CertUrl: serviceAccount.auth_provider_x509_cert_url,
  clientC509CertUrl: serviceAccount.client_x509_cert_url
};

// firebase admin
admin.initializeApp({ credential: admin.credential.cert(params) });

// firestore
const db = admin.firestore();
db.settings({
  timestampsInSnapshots: true
});

// cloud storage
const storage = new Storage({
  credentials: {
    client_email: serviceAccount.client_email,
    private_key: serviceAccount.private_key
  }
});

이상입니다

참고


  • TypeScript에서 firebase-admin sdk 사용 - 롭
  • 객체 업로드  | Cloud Storage |  Google Cloud
  • 좋은 웹페이지 즐겨찾기