- 오류 원인
- 해결 방법
- 마치며
Error: 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.
위 에러 메시지를 보면 initializeApp()이 여러번 호출되여 발생하는 에러입니다.
해당 코드를 보시면 이런식으로 되어 있을겁니다.
const admin = require("firebase-admin");
const serviceAccount = require("../config/serviceAccount.json");
const databaseURL = "databaseURL";
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: databaseURL,
});
const admin = require("firebase-admin");
const serviceAccount = require("../config/serviceAccount.json");
const databaseURL = "databaseURL";
if (!admin.apps.length) {
var firebaseAdmin = admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: databaseURL,
});
}