Skip to content

Instantly share code, notes, and snippets.

View alan89's full-sized avatar
💭
Everything on its right place

Alan Escobar alan89

💭
Everything on its right place
View GitHub Profile
@alan89
alan89 / sendCustomActionEmail.js
Last active August 24, 2021 02:00
This is a firebase cloud function example that sends a custom action email through Sendgrid.
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const sgMail = require('@sendgrid/mail');
// Using @sendgrid/mail
// TODO: Configure the `sendgrid.key` and `sendgrid.template` Google Cloud environment variables.
const API_KEY = functions.config().sendgrid.key;
const TEMPLATE_ID = functions.config().sendgrid.template;
sgMail.setApiKey(API_KEY);
const admin = require('firebase-admin');
// expects the environment variable GOOGLE_APPLICATION_CREDENTIALS
const serviceAccount = require(process.env.GOOGLE_APPLICATION_CREDENTIALS);
const credential = admin.credential.cert(serviceAccount);
const PROJECT_ID = '<FIREBASE_PROJECT_ID>';
const app = admin.initializeApp({
credential: credential
@alan89
alan89 / index.js
Created December 27, 2019 17:42 — forked from torresalmonte/index.js
Script to delete Storage rulesets using the "firebaserules" REST API
const admin = require('firebase-admin');
const {sleep} = require('sleep');
// asumes the existance of the GOOGLE_APPLICATION_CREDENCIAL env variable
const firebaseApp = admin.initializeApp();
async function getRulesets(projectId, firebaseApp, pageToken) {
pageToken = pageToken || '';
@alan89
alan89 / README.md
Created November 5, 2019 23:51 — forked from mbleigh/README.md

Fetch All Files from Firebase Hosting

This script fetches all of the files from the currently deployed version of a Firebase Hosting site. You must be signed in via the Firebase CLI and have "Site Viewer" permission on the site in question to be able to properly run the script.

Running via NPX

npx https://gist.github.com/mbleigh/9c8680cf319ace2f506f57380da66e7d <site_name>
@alan89
alan89 / index.js
Created October 15, 2019 01:50
Cloud function to send custom emails using nodemailer and the Firebase adminSDK when a user is created
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const nodemailer = require('nodemailer');
// Configure the email transport using the default SMTP transport and a GMail account.
// For other types of transports such as Sendgrid see https://nodemailer.com/transports/
// TODO: Configure the `gmail.email` and `gmail.password` Google Cloud environment variables.
const gmailEmail = functions.config().google.email;
const gmailPassword = functions.config().google.password;
// This example just includes two functions to illustrate how to split write operations
// in a series of WriteBatch ones, in order to avoid the 500 writes limit per execution
// https://firebase.google.com/docs/firestore/manage-data/transactions#batched-writes
// splitWriteBatch creates the document references to set the values and write the
// data in a series of WriteBatch operations.
// In this example, we write 650 documents, divided in 2 chunks
public void splitWriteBatch() {
// First we need to work with the data to write.
// We created the reference for those documents
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const axios = require('axios');
admin.initializeApp();
async function adminAuthEmailRequest(request) {
var token = await admin.apps[0].INTERNAL.getToken();
var requestCopy = JSON.parse(JSON.stringify(request));
requestCopy.headers = requestCopy.headers || {};
var authHeader = 'Authorization';
[
{
"name":"Aguascalientes",
"latitude":"21.883186",
"longitude":"-102.2912995"
},
{
"name":"Baja California",
"latitude":"32.378082",
"longitude":"-116.8240951"