How to use the firebase-admin.initializeApp function in firebase-admin

To help you get started, we’ve selected a few firebase-admin 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 firebase / functions-samples / google-sheet-sync / functions / index.js View on Github external
* Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
'use strict';

// Sample trigger function that copies new Firebase data to a Google Sheet

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const { OAuth2Client } = require('google-auth-library');
const google = require('googleapis');

admin.initializeApp(functions.config().firebase);
const db = admin.database();

// TODO: Use firebase functions:config:set to configure your googleapi object:
// googleapi.client_id = Google API client ID, 
// googleapi.client_secret = client secret, and 
// googleapi.sheet_id = Google Sheet id (long string in middle of sheet URL)
const CONFIG_CLIENT_ID = functions.config().googleapi.client_id;
const CONFIG_CLIENT_SECRET = functions.config().googleapi.client_secret;
const CONFIG_SHEET_ID = functions.config().googleapi.sheet_id;

// TODO: Use firebase functions:config:set to configure your watchedpaths object:
// watchedpaths.data_path = Firebase path for data to be synced to Google Sheet
const CONFIG_DATA_PATH = functions.config().watchedpaths.data_path;

// The OAuth Callback Redirect.
const FUNCTIONS_REDIRECT = `https://${process.env.GCLOUD_PROJECT}.firebaseapp.com/oauthcallback`;
github TarikHuber / react-most-wanted / functions / db / users / onUpdate.f.js View on Github external
const functions = require('firebase-functions');
const admin = require('firebase-admin');
try {admin.initializeApp(functions.config().firebase);} catch(e) {} // You do that because the admin SDK can only be initialized once.
const userSync = require('./userSync');

exports = module.exports = functions.database.ref('/users/{userUid}').onUpdate(
  (event) => {
    return Promise.all([
      userSync.syncPublicTasks(event, admin),
      userSync.syncPublicChats(event, admin)
    ])
  }
)
github marsalad / faceSwapGifs / functions / index.js View on Github external
// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');

// The Firebase Admin SDK to access the Firebase Realtime Database. 
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

// The GIPHY SDK
const giphy = require('giphy-js-sdk-core');
const client = giphy(functions.config().giphy.key);

// CORS to avoid header errors
const cors = require('cors')({ origin: true });

// query GIPHY for trending or general search
exports.queryGiphy = functions.https.onRequest((req, res) => {
  cors(req, res, () => {
    var query = req.query.query;
    var limit = req.query.limit;

    if (query) {
      client.search('gifs', {'q': query, 'limit': limit})
github Kesin11 / Firestore-simple / src / onsnapshot.ts View on Github external
import admin, { ServiceAccount } from 'firebase-admin'
import { FirestoreSimple } from '.'
import serviceAccount from '../firebase_secret.json'

interface User {
  id: string
  age: number
  name: string,
  createdAt: Date
}

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount as ServiceAccount),
})
const firestore = admin.firestore()
firestore.settings({ timestampsInSnapshots: true })

const userDao = new FirestoreSimple({ firestore, path: 'user' })

const docObserver = userDao.collectionRef.doc('1').onSnapshot((docSnapshot) => {
  console.log('Received doc snapshot: ', docSnapshot.data())
})

const collectionObserver = userDao.collectionRef
  .onSnapshot((querySnapshot) => {
    querySnapshot.docChanges.forEach((change) => {
      if (change.type === 'added') {
        console.log(`added: ${change.doc.id}`, change.doc.data())
github dalenguyen / serverless-rest-api / functions / src / index.ts View on Github external
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import * as firebaseHelper from 'firebase-functions-helper/dist';
import * as express from 'express';
import * as bodyParser from "body-parser";

admin.initializeApp(functions.config().firebase);
const db = admin.firestore();

const app = express();
const main = express();

main.use(bodyParser.json());
main.use(bodyParser.urlencoded({ extended: false }));
main.use('/api/v1', app);

const contactsCollection = 'contacts';

export const webApi = functions.https.onRequest(main);

interface Contact {
    firstName: String
    lastName: String
github machinelabs / machinelabs / firebase / functions / index.js View on Github external
const admin = require('firebase-admin');
const functions = require('firebase-functions');
admin.initializeApp(functions.config().firebase);

const assignServer = require('./assign-server');
const postLabWrite = require('./post-lab-write');
const postExecutionWrite = require('./post-execution-write');

exports.assignServer = assignServer;
exports.postLabWrite = postLabWrite;
exports.postExecutionWrite = postExecutionWrite;
github goemen / react-material-ui-typescript / functions-src / index.js View on Github external
const functions = require('firebase-functions');
const admin = require('firebase-admin');
import { CONFIG } from './config';
import * as _ from 'lodash';
admin.initializeApp(functions.config().firebase);

exports.addAdminClaimToUser = functions.auth.user().onCreate(event => {
    
    if (_.includes(CONFIG.adminUsersEmails, event.email)) {
        return admin.auth().setCustomUserClaims(event.uid, {
            admin: true
        });
    } else {
        return;
    }
});

exports.addEventToUser = functions.firestore.document('events/{id}').onCreate(async (event, context)=> {
    try {
        const data = event.data();
        if (!data.createdBy) {
github tsirlucas / PayIt / functions / src / index.ts View on Github external
import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';

admin.initializeApp(functions.config().firebase);

export * from './updateAllPendencies';
export * from './onBillChange';
export * from './sendPendenciesAlerts';
export * from './onPaydayChange';
github nkjm / bot-express / module / logger / firestore.js View on Github external
throw new Error(`Required option "${req_opt}" for LoggerFirestore not set.`);
            }
        }

        const firebase_config = {
            credential: firebase_admin.credential.cert({
                projectId: options.project_id,
                clientEmail: options.client_email,
                privateKey: options.private_key.replace(/\\n/g, "\n")
            }),
            databaseURL: `https://${options.project_id}.firebaseio.com`,
            storageBucket: `${options.project_id}.appspot.com`,
            projectId: options.project_id
        }
        try {
            firebase_admin.initializeApp(firebase_config)
        } catch(e){
            if (e.code === "app/duplicate-app"){
                debug(`Default firebase app already exists so we create another one.`)
                firebase_admin.initializeApp(firebase_config, "bot-express")
            }
        }

        this.db = firebase_admin.firestore()
        memory_cache.put("firestore", this.db)
    }
github alvarowolfx / weather-station-gcp-mongoose-os / functions / index.js View on Github external
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const bigquery = require('@google-cloud/bigquery')();
const cors = require('cors')({ origin: true });

admin.initializeApp(functions.config().firebase);

const db = admin.database();

/**
 * Receive data from pubsub, then 
 * Write telemetry raw data to bigquery
 * Maintain last data on firebase realtime database
 */
exports.receiveTelemetry = functions.pubsub
  .topic('telemetry-topic')
  .onPublish((message, context) => {
    const attributes = message.attributes;
    const payload = message.json;

    const deviceId = attributes['deviceId'];