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 init = (action, store) => {
try {
firebase.initializeApp(config)
// enable firestore
firebase.firestore()
// enable function calls
firebase.functions()
initFunctionCalls()
} catch (error) {
console.warn(error.code, error.message)
}
firebase.auth().onAuthStateChanged(user => {
if (user) {
store.dispatch({ type: '@@firebase/SIGNED_IN', payload: user })
preloadFunctions()
} else {
store.dispatch('@@firebase/SIGNED_OUT')
}
})
}
console.log('====================================')
}
// - Storage reference
export let storageRef = firebase.storage().ref()
// Initialize Cloud Firestore through Firebase
const db = firebase.firestore()
const settings = {}
db.settings(settings)
export {
db
}
// - Database authorize
export let firebaseAuth = firebase.auth
export let functions = firebase.functions()
// export let firebaseRef = firebase.database().ref()
// - Firebase default
export default firebase
export default (initialState = {}) => {
// Pick between dev and prod firebase configurations
const selectedFirebaseConfig = firebaseConfig[process.env.NODE_ENV];
// Initialize firebase instance
firebase.initializeApp(selectedFirebaseConfig);
// Initialize Cloud Functions to firebase instance
firebase.functions();
firebase.nwUtils = {
// Define a function for fetching a cloud function's URL given its name
getFunctionUrl: (functionName) => {
if (process.env.NODE_ENV === 'development') {
return `http://localhost:5000/${selectedFirebaseConfig.projectId}/us-central1/${functionName}`;
} // production
return `https://us-central1-${selectedFirebaseConfig.projectId}.cloudfunctions.net/${functionName}`;
},
};
// Initialize Cloud Firestore through Firebase
const firestore = firebase.firestore();
const firestoreSettings = { timestampsInSnapshots: true };
firestore.settings(firestoreSettings);
FontsConfig.loadFonts()
log.debug("init firebase")
firebase.initializeApp({
apiKey: "AIzaSyDu0Zg8VmVa664dCTWErmcn3yDE1OJBfs0",
authDomain: "forge-of-the-archons.firebaseapp.com",
databaseURL: "https://forge-of-the-archons.firebaseio.com",
projectId: "forge-of-the-archons",
storageBucket: "forge-of-the-archons.appspot.com",
messagingSenderId: "81787944178",
appId: "1:81787944178:web:36aa683bc37bfedc"
})
if (isDev) {
firebase.functions().useFunctionsEmulator("http://localhost:5000")
}
WebFont.load({
google: {
families: ["Roboto:300,400,500,700"]
},
})
ReactDOM.render(, document.getElementById("root"))
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister()
authStore.listenForAuthUser()
async onAdminAnalyse(uid, adminCustomAnalysisID, queries) {
try {
let results = await this.getQueryResults(queries).then();
return await firebase
.functions()
.httpsCallable("runCustomAnalysis")({
uid,
solutions: results,
analysisID: adminCustomAnalysisID,
analysisType: "adminCustomAnalysis"
})
.then(response =>
this.storeAnalysis(uid, response, adminCustomAnalysisID)
)
.catch(err => console.error(err));
} catch (error) {
console.error(error.message);
}
}
}
import * as firebase from 'firebase/app'
import 'firebase/auth'
import 'firebase/firestore'
import 'firebase/functions'
import { firebaseConfig } from '../.config/firebase'
firebase.initializeApp(firebaseConfig)
export const db = firebase.firestore()
export const functions = firebase.functions()
export const authProvider = new firebase.auth.GoogleAuthProvider()
async add(isbn: string) {
try {
await Promise.all([
firebase.functions().httpsCallable('registerBook')({
uid: (firebase.auth().currentUser as firebase.User).uid,
isbn
}),
this.dismiss()
]);
} catch (error) {
await this.showError(error);
}
}
}
const buildFunctionWithTimezone = functionName => {
const cloudFunction = firebase.functions().httpsCallable(functionName)
const { timeZone } = Intl.DateTimeFormat().resolvedOptions()
return ({ userTimezone, ...rest }) =>
cloudFunction({
...rest,
userTimezone: userTimezone || timeZone,
})
}
import "firebase/storage";
const config = {
apiKey: process.env.REACT_APP_FIREBASE_PROJECT_KEY,
authDomain: `${process.env.REACT_APP_FIREBASE_PROJECT_NAME}.firebaseapp.com`,
databaseURL: `https://${process.env.REACT_APP_FIREBASE_PROJECT_NAME}.firebaseio.com`,
projectId: process.env.REACT_APP_FIREBASE_PROJECT_NAME,
storageBucket: `${process.env.REACT_APP_FIREBASE_PROJECT_NAME}.appspot.com`,
};
firebase.initializeApp(config);
export const auth = firebase.auth();
export const db = firebase.firestore();
export const bucket = firebase.storage();
export const functions = firebase.functions();
export const googleProvider = new firebase.auth.GoogleAuthProvider();
export const uploadEntities = (entities, sectorId) =>
Firebase.functions()
.httpsCallable('saveEntities')({ sectorId, entities })
.then(({ data }) => data);