How to use the firebase.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 zeit / next.js / examples / z-experimental-next-news / lib / db.js View on Github external
import firebase from 'firebase'

try {
  firebase.initializeApp({
    databaseURL: 'https://hacker-news.firebaseio.com',
  })
} catch (err) {
  // we skip the "already exists" message which is
  // not an actual error when we're hot-reloading
  if (!/already exists/.test(err.message)) {
    console.error('Firebase initialization error', err.stack)
  }
}

const root = firebase.database().ref('v0')

export default root
github leejh3224 / react-native-hello-talk / src / screens / Auth / register.tsx View on Github external
onSubmit = async (values: FormValues) => {
    try {
      const { navigation } = this.props;

      const user = navigation.getParam("userData");

      values.age = new Date().getFullYear() - values.birthday.getFullYear();
      delete values.birthday;

      if (user) {
        await firebase
          .database()
          .ref(`users/${user.uid}`)
          .set({
            ...values,
            description: "",
            profileImage: user.photoURL,
            lastActiveTime: Date.now(),
            country: Localization.country
          });

        navigation.navigate(getNavigationKey(["chat", "home"]));
      }
    } catch (error) {
      console.log(error);
    }
  };
github magda-io / magda / magda-web-client / firebase / functions / index.js View on Github external
exports.addUserToDatabase = functions.auth.user().onCreate(event => {
  const user = event.data;

  const userData = firebase.database().ref(`/users/${user.uid}`);

  console.log(user);

  return userData
    .set(user)
    .catch(e => {
      console.error(e);
      throw e;
    });
});
github samiheikki / javascript-guessing-game / src / App.vue View on Github external
firebase.database().ref('/scores/' + this.user.uid).once('value').then((snapshot) => {
          const previousScore = snapshot.val()
          if (!previousScore || (previousScore && this.shouldSaveNewScore(objToDb, previousScore))) {
            firebase.database().ref('scores/' + this.user.uid).set(objToDb)
          }
        })
      }
github petejohanson / vuego / src / game / remote_game.js View on Github external
* Created by peter on 5/16/16.
 */

import promiseTry from 'es6-promise-try';
import firebase from 'firebase';

import { BLACK, WHITE } from './color';

firebase.initializeApp({
  apiKey: 'AIzaSyD1sB2mtSubsImIEh4SklU7EivMnJHKLDA',
  authDomain: 'vuego.firebaseapp.com',
  databaseURL: 'https://vuego.firebaseio.com',
  storageBucket: 'project-1396985000601130379.appspot.com'
});

let fb = firebase.database();

class RemoteGame {
  constructor (store) {
    this.store = store;
    let gameId = store.state.remoteGameId;

    if (!store.state[WHITE]) {
      let opponent = fb.ref(`games/${gameId}/${WHITE}`);
      let cb = snapshot => {
        if (!snapshot.val()) {
          return;
        }

        store.dispatch('remoteOpponentAccepted', { opponentId: snapshot.val() });
        opponent.off('value', cb);
      };
github aymendhaya / ra-data-firebase-client / src / lib / RestProvider.js View on Github external
const initializeResource = ({ name, isPublic }, resolve) => {
    let ref = (resourcesReferences[name] = firebase.database().ref(resourcesPaths[name]));
    resourcesData[name] = [];

    if (isPublic) {
      subscribeResource(ref, name, resolve);
    } else {
      firebase.auth().onAuthStateChanged(auth => {
        if (auth) {
          subscribeResource(ref, name, resolve);
        }
      });
    }

    setTimeout(resolve, initialQuerytimeout);

    return true;
  };
github cassioscabral / rateissuesfront / src / helpers / adapter.js View on Github external
import {FirebaseAdapter} from 'js-data-firebase'
import firebase from 'firebase'

const dataSource = 'firebase'

let config = {
  apiKey: 'AIzaSyBnrMHd4NrB3ldmvtvWBp3dnRY8BJjTOpE',
  authDomain: 'rateissue.firebaseapp.com',
  databaseURL: 'https://rateissue.firebaseio.com',
  storageBucket: 'rateissue.appspot.com',
  messagingSenderId: '442562743753'
}
firebase.initializeApp(config)

const adapter = new FirebaseAdapter({
  db: firebase.database()
})

export default adapter
export {dataSource, firebase}
github nyura123 / mobx-firebase-store / examples / next-example / store.js View on Github external
export function getFirebaseInfo(appName) {
  if (global.serverFirebase) {
    //firebase-admin
    return {app: null, ref: global.serverFirebase.database().ref()}
  } else {
    const fbApp = initFirebaseApp(appName)
    return {app: fbApp, ref: firebase.database(fbApp).ref()}
  }
}
github handsomecode / smart-foosball-iot / SlackBot / app / services / firebase.js View on Github external
'use strict';

var Firebase = require('firebase');

var firebaseConfig = require(__app + 'config')('firebase');

Firebase.initializeApp(firebaseConfig);

var firebaseDatabase = Firebase.database();

var games;

var initialisationState = 0;

module.exports = {
    getPlayers: function () {
        return new Promise(function (resolve) {
            firebaseDatabase.ref('/players/').on('value', function (snapshot) {
                resolve(snapshot.val());
            });
        });
    },

    getNewGamesListener: function (handler) {
        var self = this;