How to use the firebase-admin.app 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 celo-org / celo-monorepo / packages / faucet / src / test-driver.ts View on Github external
// await printAccounts(pool)

    // console.log('after')

    // const tx = await sendFunds({
    //   providerUrl: 'http://34.83.69.157:8545',
    //   fromPk: '0x0e08757b5e1efd8fc93e25188f2a2fea51c9bff6438729c3c7208de2169f9e7a',
    //   to: '0x193eab124b946b79461b484812dca10afb3b2294',
    //   valueEth: '0.05',
    // })
    // console.log(tx)
  } catch (err) {
    console.error('Failed')
    console.error(err)
  } finally {
    await admin.app().delete()
  }
}
github nicolasgarnier / friendlypix-web-react / microservices / blurOffensiveImages.js View on Github external
const config = {
      credential: functions.config().firebase.credential,
      databaseURL: functions.config().firebase.databaseURL,
      databaseAuthVariableOverride: {
        uid: uid
      }
    };
    app = admin.initializeApp(config, uid);
  } catch (e) {
    if (e.code !== 'app/duplicate-app') {
      console.error('There was an error initializing Firebase Admin', e);
      throw e;
    }
    // An app for that UID was already created so we re-use it.
    console.log('Re-using existing app.');
    app = admin.app(uid);
  }

  const imageUrlRef = app.database().ref(`/posts/${postId}/${size}_url`);
  return imageUrlRef.once('value').then(snap => {
    const picUrl = snap.val();
    return imageUrlRef.set(`${picUrl}&blurred`).then(() => {
      console.log('Blurred image URL updated.');
    });
  });
}
github nicolasgarnier / friendlypix-web-react / microservices / firebase-express-middleware.js View on Github external
function getDefaultFirebaseAdminApp() {
  let firebaseAdminApp;
  let appName;
  try {
    // Configure Firebase Admin.
    appName = `__service_account_${process.env.GCLOUD_PROJECT}`;
    firebaseAdminApp = admin.initializeApp({credential: admin.credential.applicationDefault()}, appName);
  } catch (e) {
    if (e.code !== 'app/duplicate-app') {
      console.error('There was an error initializing Firebase Admin with default credentials', e);
      return;
    }
    // An app for that UID was already created so we re-use it.
    console.log('Re-using existing app.');
    firebaseAdminApp = admin.app(appName);
  }
  return firebaseAdminApp;
}
github rakannimer / react-firebase / modules / generate-firestore-data / src / index.ts View on Github external
{ schema, keyReducers, count }: GenerateJsonArgs,
  { databaseURL, credential }: InitializeAppArgs
) => {
  const { project_id } = credential;
  const databaseBrowserURL = `https://console.firebase.google.com/project/${project_id}/database/firestore/data/`;
  console.log(
    `Adding Data to ${project_id}. You can watch here : ${databaseBrowserURL}`
  );
  initializeApp({
    firebase,
    databaseURL,
    credential
  });
  const { keys, values } = await generateJson({ schema, keyReducers, count });

  const firestore = firebase.app().firestore();
  const settings = { timestampsInSnapshots: true };
  firestore.settings(settings);
  const firestoreBatch = firestore.batch();
  for (let a = 0; a < keys.length; a += 1) {
    const key = keys[a];
    const { ref: leaf, leafName } = getFirestoreRefFromDottedPath({
      path: key,
      firestore
    });

    firestoreBatch.set(leaf, { [leafName]: values[a] }, { merge: true });
    if (a % FIRESTORE_BATCH_LIMIT === 0 && a > 0) {
      await firestoreBatch.commit();
    }
  }
  await firestoreBatch.commit();
github naveedaheer / Sale-Purchase-Stock-Inventory-App-in-React / functions / node_modules / firebase-functions / lib / apps.js View on Github external
Apps.prototype.forMode = function (auth) {
            if (typeof auth !== 'object') {
                return this.noauth;
            }
            if (auth.admin) {
                return this.admin;
            }
            if (!auth.variable) {
                return this.noauth;
            }
            var appName = this._appName(auth);
            if (this._appAlive(appName)) {
                return firebase.app(appName);
            }
            var param = _.extend({}, this.firebaseArgs, {
                databaseAuthVariableOverride: auth.variable,
            });
            return firebase.initializeApp(param, appName);
        };
        Object.defineProperty(Apps.prototype, "firebaseArgs", {
github naveedaheer / Sale-Purchase-Stock-Inventory-App-in-React / functions / node_modules / firebase-functions / lib / apps.js View on Github external
Apps.prototype._destroyApp = function (appName) {
            if (!this._appAlive(appName)) {
                return;
            }
            firebase.app(appName).delete().catch(_.noop);
        };
        Apps.prototype.retain = function (payload) {
github kaliberjs / build / example / src / index.html.js View on Github external
function getApp () {
    const name = 'build-example-app'
    try { return firebase.app(name) } catch (e) {
      const { credentials, databaseURL } = config.server.firebase
      return firebase.initializeApp(
        {
          credential: firebase.credential.cert(credentials),
          databaseURL
        },
        name
      )
    }
  }
}
github firebase / firebase-functions / src / apps.ts View on Github external
get admin(): firebase.app.App {
      if (this._appAlive('__admin__')) {
        return firebase.app('__admin__');
      }
      return firebase.initializeApp(this.firebaseArgs, '__admin__');
    }
github firebase / firebase-functions / src / apps.ts View on Github external
_appAlive(appName: string): boolean {
      try {
        const app = firebase.app(appName);
        return !_.get(app, 'isDeleted_');
      } catch (e) {
        return false;
      }
    }