How to use the firebase/app.database function in firebase

To help you get started, we’ve selected a few firebase examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github okwme / eac-chat / src / api / firebase.js View on Github external
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
github NUS-ALSET / achievements / src / services / actions.js View on Github external
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
    ) {
github tylermcginnis / re-base / tests / specs / rtdb / syncState.spec.js View on Github external
beforeEach(() => {
    app = firebase.initializeApp(firebaseConfig);
    var db = firebase.database(app);
    base = Rebase.createClass(db);
  });
github swaponline / swap.react / shared / redux / actions / firebase / index.js View on Github external
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)
      })
  })
github swaponline / swap.react / shared / helpers / firebase / index.js View on Github external
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)
      })
  })
github NUS-ALSET / achievements / src / services / courses.js View on Github external
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()
          )
        )
      );
  }
github sidferreira / aor-firebase-client / src / methods.js View on Github external
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;
};
github NUS-ALSET / achievements / src / services / tasks.js View on Github external
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() || {}) }))
          )
        )
      );
  }
github NUS-ALSET / achievements / src / services / courses.js View on Github external
removeAssistant(courseId, assistantId) {
    return firebase
      .database()
      .ref(`/courseAssistants/${courseId}/${assistantId}`)
      .remove();
  }
github carlelieser / Flixerr / assets / js / app.jsx View on Github external
createDataBase = () => {
        if (this.state.user) {
            let db = firebase.database();
            this.databaseRef = db.ref(`users/${this.state.user.uid}`);
        }
    };