Skip to content

Instantly share code, notes, and snippets.

katowulf / client-index.ts
Last active May 9, 2019
Example of validating Firestore writes using Cloud Functions endpoints
View client-index.ts
import './style.css';
import logger from './logger'; // see
import {sendRequest} from './request';
const endpoint = '';
const data = {
string: 'foo',
integer: 23,
boolean: false,
katowulf / client.js
Last active May 9, 2019
Firestore security rules validation example
View client.js
import * as firebase from "firebase/app";
import 'firebase/firestore';
import config from './config';
const data = {
string: 'foo',
integer: 23,
boolean: false,
katowulf / create_user_functions.js
Created Dec 3, 2018
Create a Firebase user from an authenticated Cloud Functions HTTPS endpoint.
View create_user_functions.js
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const express = require('express');
const cookieParser = require('cookie-parser')();
const cors = require('cors')({origin: true});
const app = express();
// See
const validateFirebaseIdToken = require('./validateFirebaseIdToken');
katowulf / rules.js
Created Nov 16, 2018
Group inheritance and doc sharing in Firebase rules. See
View rules.js
"rules": {
".read": false,
".write": false,
"roles-example": {
// grant global read to our admin tools
".read": "auth.uid === 'ACCESS_MANAGER'",
// The documents which we are restricting access to
"docs": {
katowulf / call.js
Last active Jun 4, 2019
Modular Functions layout for Firebase
View call.js
export const run = (data, context) => {
const path = data.path;
if( path !== "bar" ) {
throw new functions.https.HttpsError('invalid-argument', "Path was not valid");
return {foo: "bar"};
katowulf /
Last active Aug 20, 2020
Enable debug logging in Firestore in Java, Javascript, or Swift.
/******* Android **********/
// See
/******* Server-side Java **********/
1) Add the slf4j-simple binding to the application classpath
2) Set the -Dorg.slf4j.simpleLogger.defaultLogLevel=debug system property
katowulf / functions_index.js
Last active Jan 31, 2020
Upload file to Storage, add custom metadata, and fetch that metadata in Functions
View functions_index.js
const functions = require('firebase-functions');
const util = require('util');
const admin = require('firebase-admin');
exports.uploadedFile = => {
console.log('object keys', Object.keys(uploadedObject));
// This contains the custom metadata
console.log('metedata keys', Object.keys(uploadedObject.metadata));
katowulf / delete_users_throttled.js
Created Mar 6, 2018
Delete users in Firebase Authentication using Admin SDK
View delete_users_throttled.js
const admin = require('firebase-admin');
const serviceAccount = require('path/to/serviceAccountKey.json');
// User IDs to be deleted
const UIDs = [];
// initialize the app
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://<DATABASE_NAME>'
katowulf / app.component.ts
Last active Jul 8, 2020
Dynamically set page title based on active route in Angular 4
View app.component.ts
// This can probably be simplified somehow. Not sure why I need to add it in the component to init the service.
import { Component, OnInit } from '@angular/core';
import {TitleService} from "./@core/utils/title.service";
export class AppComponent implements OnInit {
constructor(private titleService: TitleService) {...}
View data_structure.json
"albums": {
"key1": {
"owner": "uid1",
"subscribers": {
"uid1": true,
"uid2": true
You can’t perform that action at this time.