79 lines
2.2 KiB
JavaScript
79 lines
2.2 KiB
JavaScript
import * as Analytics from "expo-firebase-analytics";
|
|
import * as firebase from "firebase/app";
|
|
import "firebase/auth";
|
|
import { store } from "../redux/store";
|
|
|
|
//const config = JSON.parse(process.env.REACT_APP_FIREBASE_CONFIG);
|
|
// const config = {
|
|
// apiKey: "AIzaSyDPLT8GiDHDR1R4nI66Qi0BY1aYviDPioc",
|
|
// authDomain: "imex-dev.firebaseapp.com",
|
|
// databaseURL: "https://imex-dev.firebaseio.com",
|
|
// projectId: "imex-dev",
|
|
// storageBucket: "imex-dev.appspot.com",
|
|
// messagingSenderId: "759548147434",
|
|
// appId: "1:759548147434:web:e8239868a48ceb36700993",
|
|
// measurementId: "G-K5XRBVVB4S",
|
|
// };
|
|
|
|
const config = {
|
|
apiKey: "AIzaSyDSezy-jGJreo7ulgpLdlpOwAOrgcaEkhU",
|
|
authDomain: "imex-prod.firebaseapp.com",
|
|
databaseURL: "https://imex-prod.firebaseio.com",
|
|
projectId: "imex-prod",
|
|
storageBucket: "imex-prod.appspot.com",
|
|
messagingSenderId: "253497221485",
|
|
appId: "1:253497221485:web:3c81c483b94db84b227a64",
|
|
measurementId: "G-NTWBKG2L0M",
|
|
};
|
|
|
|
if (!firebase.apps.length) {
|
|
firebase.initializeApp(config);
|
|
}
|
|
|
|
export const auth = firebase.auth();
|
|
//export const analytics = firebase.analytics();
|
|
|
|
export default firebase;
|
|
|
|
export const getCurrentUser = () => {
|
|
return new Promise((resolve, reject) => {
|
|
const unsubscribe = auth.onAuthStateChanged((userAuth) => {
|
|
unsubscribe();
|
|
resolve(userAuth);
|
|
}, reject);
|
|
});
|
|
};
|
|
|
|
export const updateCurrentUser = (userDetails) => {
|
|
return new Promise((resolve, reject) => {
|
|
const unsubscribe = auth.onAuthStateChanged((userAuth) => {
|
|
userAuth.updateProfile(userDetails).then((r) => {
|
|
unsubscribe();
|
|
resolve(userAuth);
|
|
});
|
|
}, reject);
|
|
});
|
|
};
|
|
|
|
export const logImEXEvent = (eventName, additionalParams, stateProp = null) => {
|
|
const state = stateProp || store.getState();
|
|
const eventParams = {
|
|
shop:
|
|
(state.user && state.user.bodyshop && state.user.bodyshop.shopname) ||
|
|
null,
|
|
user:
|
|
(state.user && state.user.currentUser && state.user.currentUser.email) ||
|
|
null,
|
|
...additionalParams,
|
|
};
|
|
console.log(
|
|
"%c[Analytics]",
|
|
"background-color: green ;font-weight:bold;",
|
|
eventName,
|
|
eventParams
|
|
);
|
|
Analytics.logEvent(eventName, eventParams);
|
|
};
|
|
|
|
//export const ExpoAnalytics = Analytics;
|