Firebase 連携

1import { initializeApp, getApps } from 'firebase/app';
2import { Analytics, getAnalytics } from 'firebase/analytics';
3import { getFirestore } from 'firebase/firestore';
4import { getStorage } from 'firebase/storage';
5import { getAuth } from 'firebase/auth';
6import { getFunctions } from 'firebase/functions';
7
8const config = JSON.parse(
9  process.env.NEXT_PUBLIC_FIREBASE_CLIENT_CONFIG as string
10);
11
12export let ga: Analytics;
13
14if (!getApps()?.length) {
15  initializeApp(config);
16
17  if (typeof window !== 'undefined' && 'measurementId' in config) {
18    ga = getAnalytics();
19  }
20}
21
22export const db = getFirestore();
23export const storage = getStorage();
24export const auth = getAuth();
25export const fns = getFunctions(undefined, 'asia-northeast2');