Skip to content

Instantly share code, notes, and snippets.

@ivanfgm
Created March 17, 2022 20:56
Show Gist options
  • Save ivanfgm/ef582dc92a30cc896aeb52645bacd3ff to your computer and use it in GitHub Desktop.
Save ivanfgm/ef582dc92a30cc896aeb52645bacd3ff to your computer and use it in GitHub Desktop.
Use Firebase Admin SDK inside a Next.js project.
// I usually put this in config/firebaseAdmin.js
import * as admin from 'firebase-admin'
// You need your account service key json file inlined in .env
let serviceAccount = JSON.parse(process.env.FIREBASE_ACCOUNTKEY)
let config = {
credential: admin.credential.cert(serviceAccount)
}
export default !admin.apps.length ? admin.initializeApp(config) : admin;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment