I have some firebase functions that I test locally, but I really don't want to have to rely on remembering to switch a flag, or explicitly set the values. Is there a value I can check in firebase to tell if it's in dev or prod? I'm also using NextJS, so I don't mind changing it on the next side either. Just whatever way makes the most sense within the firebase ecosystem. Thanks!
The invocation of client inside my function (on firebase):
const env = new checkoutNodeSDK.core.SandboxEnvironment(clientId, clientSecret)
My firebase.js file:
import firebase from 'firebase/app'
import 'firebase/auth'
import 'firebase/firestore'
import 'firebase/functions'
const dev = true
export const app = !firebase.apps.length ? firebase.initializeApp({
apiKey: "REDACTED",
authDomain: "edit-elements.firebaseapp.com",
databaseURL: "https://edit-elements-default-rtdb.firebaseio.com",
projectId: "edit-elements",
storageBucket: "edit-elements.appspot.com",
messagingSenderId: "340652433701",
appId: "1:340652433701:web:a26472592c1538bbac7acc",
measurementId: "G-945XC7348K"
}) : firebase.app()
const auth = app.auth()
const db = app.firestore()
const functions = app.functions()
if (process.env.NODE_ENV === 'development') {
functions.useEmulator('localhost', 5001)
db.useEmulator('localhost', 8080)
}
export { auth, db, functions }
I want to set something like:
const env = flagDev ? new checkoutNodeSDK.core.SandboxEnvironment(clientId, clientSecret) : new checkoutNodeSDK.core.LiveEnvironment(clientId, clientSecret)
TL;DR - When the function is called in dev, I want the function to use the Sandbox credentials. In prod, I want to use the live sandbox credentials.