Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import firebase from 'firebase/app'
import 'firebase/auth'
import 'firebase/database'
var config = {
apiKey: 'AIzaSyAdK9qrNj1G6abHZiYkyDvdJ3pajUnBtS8',
authDomain: 'eac-chat-ddecb.firebaseapp.com',
databaseURL: 'https://eac-chat-ddecb.firebaseio.com',
projectId: 'eac-chat-ddecb',
storageBucket: 'eac-chat-ddecb.appspot.com',
messagingSenderId: '453164258119'
}
firebase.initializeApp(config)
export const db = firebase.database()
// export const db = firebase.firestore()
// Disable deprecated features
// db.settings({
// timestampsInSnapshots: true
// })
export const fb = firebase
catchAction = () => next => action => {
const currentUserId =
firebase.auth().currentUser && firebase.auth().currentUser.uid;
if (this.consumerKey === undefined && currentUserId) {
this.consumerKey = "";
firebase
.database()
.ref(`/users/${currentUserId}/consumerKey`)
.once("value")
.then(data => (this.consumerKey = data.val() || ""));
}
const data = {};
if (this.consumerKey) {
data.consumerKey = this.consumerKey;
}
if (
action.type &&
// Ignore react-redux-firebase builtin actions
action.type.indexOf("@@reactReduxFirebase") === -1 &&
!this.bannedActions.includes(action.type) &&
currentUserId
) {
beforeEach(() => {
app = firebase.initializeApp(firebaseConfig);
var db = firebase.database(app);
base = Rebase.createClass(db);
});
new Promise(async (resolve) => {
const database = isDefault
? firebase.database()
: firebase.database(window.clientDBinstance)
const usersRef = database.ref(dataBasePath)
usersRef.child(userId).set(data)
.then(() => resolve(true))
.catch((error) => {
console.log('Send error: ', error)
resolve(false)
})
})
new Promise(async (resolve) => {
const database = isDefault
? firebase.database()
: firebase.database(window.clientDBinstance)
const usersRef = database.ref(dataBasePath)
usersRef.child(userId).set(data)
.then(() => resolve(true))
.catch((error) => {
console.log('Send error: ', error)
resolve(false)
})
})
unWatchCourseMembers(courseId) {
return firebase
.database()
.ref(`/courseMembers/${courseId}`)
.once("value")
.then(members =>
Promise.all(
Object.keys(members.val() || {}).map(id =>
firebase
.database()
.ref(`/userAchievements/${id}`)
.off()
)
)
);
}
const getId = (params, resourceData, type, resourcePath) => {
let id = params.data.id || params.id;
if (!id) {
id = firebase
.database()
.ref()
.child(resourcePath)
.push().key;
}
if (!id) {
throw new Error("ID is required");
}
if (resourceData && resourceData[id] && type === CREATE) {
throw new Error("ID already in use");
}
return id;
};
fetchPresets() {
return firebase
.database()
.ref("/config/taskPresets")
.once("value")
.then(snap => snap.val() || {})
.then(presets =>
Promise.all(
Object.keys({ ...presets, basic: presets.basic || BASIC_PRESET }).map(presetId =>
firebase
.database()
.ref(`/tasks/${presetId}`)
.once("value")
.then(snap => ({ id: presetId, ...(snap.val() || {}) }))
)
)
);
}
removeAssistant(courseId, assistantId) {
return firebase
.database()
.ref(`/courseAssistants/${courseId}/${assistantId}`)
.remove();
}
createDataBase = () => {
if (this.state.user) {
let db = firebase.database();
this.databaseRef = db.ref(`users/${this.state.user.uid}`);
}
};