Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const initFirebase = (rootKey, authToken) => {
const firebaseAppName = `App-${rootKey}`;
/* Check if we've already initialized an Firebase App with the */
/* same name in this local environment */
const existingApp = firebase.apps.reduce((prev, curr) => {
return curr.name === firebaseAppName ? curr : prev;
}, undefined);
/* Use the existing Firebase App or initialize a new one */
const firebaseApp = existingApp || firebase.initializeApp(getFirebaseConfig(), firebaseAppName);
const database = firebase.database(firebaseApp);
/* Authenticate with the server-generated token */
return firebase
.auth(firebaseApp)
.signInWithCustomToken(authToken)
.then(() => {
return [database.ref(`${rootKey}`), database.ref('.info/connected')];
})
.catch((err) => {
console.error('Error authenticating firebase', err);
async function getFirebase() {
if (!firebase.apps.length) {
const { publicRuntimeConfig } = getConfig()
// These variables are defined in `env-config.js` file in the parent directory.
firebase.initializeApp(publicRuntimeConfig.FIREBASE_CONFIG)
}
return firebase
}
return firebase
.auth()
.setPersistence(firebase.auth.Auth.Persistence.LOCAL)
.then(() => firebase.auth().signInWithPopup(provider))
.catch(console.error)
}
export function loginGitHub() {
const provider = new firebase.auth.GithubAuthProvider()
provider.setCustomParameters({
allow_signup: 'true'
})
return login(provider)
}
export default firebase.apps.length ? firebase : null
import firebase from 'firebase/app'
import 'firebase/firestore'
import 'firebase/auth'
if (!firebase.apps.length) {
firebase.initializeApp({
apiKey: process.env.APIKEY,
authDomain: process.env.AUTHDOMAIN,
databaseURL: process.env.DATABASEURL,
projectId: process.env.PROJECTID,
storageBucket: process.env.STORAGEBUCKET,
messagingSenderId: process.env.MESSAGINGSENDERID,
appId: process.env.APPID
})
}
export default (context, inject) => {
inject('firebase', firebase)
inject('firestore', firebase.firestore())
inject('auth', firebase.auth())
}
import firebase from "firebase/app";
import "firebase/auth";
const config = {
apiKey: process.env.NUXT_ENV_API_KEY,
authDomain: process.env.NUXT_ENV_AUTH_DOMAIN,
databaseURL: process.env.NUXT_ENV_DATABASE_URL,
projectId: process.env.NUXT_ENV_PROJECT_ID,
storageBucket: process.env.NUXT_ENV_STORAGE_BUCKET,
messagingSenderId: process.env.NUXT_ENV_MESSAGE_SENDER_ID,
appId: process.env.NUXT_ENV_APP_ID
};
!firebase.apps.length ? firebase.initializeApp(config) : "";
export const auth = firebase.auth();
const appIsInitialized = () => firebase.apps.length && firebase.apps.length > 0
import firebase from 'firebase/app';
import 'firebase/firestore';
const config = {
apiKey: 'AIzaSyD-sz6tSPCKKhQBJnl1SuAzrnMktnMOFSI',
authDomain: 'tanam-dev.firebaseapp.com',
databaseURL: 'https://tanam-dev.firebaseio.com',
projectId: 'tanam-dev',
storageBucket: 'tanam-dev.appspot.com',
messagingSenderId: '2622678578'
};
const firebaseApp = !firebase.apps.length
? firebase.initializeApp(config)
: firebase.app();
const firestore = firebaseApp.firestore();
firestore.settings({ timestampsInSnapshots: true });
export { firestore };
export default () => {
if (!firebase.apps.length) {
firebase.initializeApp(process.env.firebaseConfig);
}
const firestore = firebase.firestore();
const settings = {};
firestore.settings(settings);
}
render() {
const { render, config } = this.props;
const firebaseApp = firebase.apps.length
? firebase.apps[0]
: firebase.initializeApp(config);
return render(firebaseApp);
}
}
const firebase = require("firebase/app");
require("firebase/auth");
const firebaseConfig = require('../../env/env.firebase');
if (firebase.apps.length === 0) {
firebase.initializeApp(firebaseConfig);
}
module.exports = { firebase };