Skip to content

Instantly share code, notes, and snippets.

@harrylincoln
harrylincoln / app.module.ts
Created July 12, 2017 20:45
App module bootstrapping angularfire2 functionality
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { AngularFireModule } from 'angularfire2';
import { AngularFireDatabaseModule } from 'angularfire2/database';
import { AngularFireAuthModule } from 'angularfire2/auth';
import { environment } from '../environments/environment';
import { RegisterComponent } from './register/register.component';
@harrylincoln
harrylincoln / app.component.ts
Created July 12, 2017 20:47
Component with focus on the constructor
import { Component } from '@angular/core';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
import { AF } from '../providers/af';
import { HttpModule } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { AngularFireAuthModule, AngularFireAuth } from 'angularfire2/auth';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
@harrylincoln
harrylincoln / app.component.ts
Last active July 12, 2017 20:52
Extended component with createNewUser function
import { Component } from '@angular/core';
import { AngularFireDatabase, FirebaseListObservable } from 'angularfire2/database';
import { AF } from '../providers/af';
import { HttpModule } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import { AngularFireAuthModule, AngularFireAuth } from 'angularfire2/auth';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
@harrylincoln
harrylincoln / app.component.html
Created July 12, 2017 21:42
Html snippet to give context to createNewUserHit
...
<h2>Example 1</h2>
<button (click)="createNewUserHit($event)">Create a user via backend</button>
<button (click)="signInEmailPassHit($event)">Sign in using email and pass</button>
...
@harrylincoln
harrylincoln / af.ts
Last active July 12, 2017 22:04
Angularfire injectable provider
import {Injectable} from "@angular/core";
import { Observable } from 'rxjs/Observable';
import { FirebaseObjectFactoryOpts } from "angularfire2/interfaces";
import { AngularFireDatabaseModule, AngularFireDatabase, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2/database';
import { AngularFireAuthModule, AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';
import { Headers, Http, RequestOptions } from '@angular/http';
import 'rxjs/add/operator/toPromise';
@Injectable()
@harrylincoln
harrylincoln / routes.js
Last active July 12, 2017 22:16
Express route for creating user via firebase admin
const express = require('express');
const router = express.Router();
const admin = require('firebase-admin');
const db = admin.database();
...
router.use('/create-user', (req, res) => {
console.log('createUser: req', req.body);
admin.auth().createUser({
email: req.body.emailAddress,
emailVerified: false,
@harrylincoln
harrylincoln / af.ts
Created July 13, 2017 16:34
Get a token ID so our BE knows you're legit
...
getTokenAndSendToAPI() {
this.afAuth.auth.currentUser.getToken().then(idToken => {
this.tokenID = idToken;
console.log('getTokenAndSendToAPI() idToken', this.tokenID);
let headersObj = new Headers();
headersObj.append('Authorization', 'Bearer ' + this.tokenID)
let options = new RequestOptions({ headers: headersObj });
@harrylincoln
harrylincoln / routes.js
Created July 13, 2017 16:46
/api routes and the authentication handled by the brilliant express-firebase-middleware
...
router.use('/api', cors(), firebaseMiddleware.auth);
router.get('/api/hello', (req, res) => {
res.json({
message: `You're logged in as ${res.locals.user.email} with Firebase UID: ${res.locals.user.uid}`
});
});
...
@harrylincoln
harrylincoln / webpack.config.js
Created July 18, 2017 13:17
Monk, yeahhhhhh
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const path = require('path');
let prod = process.argv.indexOf('-p') !== -1;
let watchOption = process.argv.indexOf('--watch') !== -1;
module.exports = {
entry: ['./js/site.js'],
output: {
@harrylincoln
harrylincoln / fake-bubz.js
Created September 25, 2019 10:13
fake bubz
var SURNAME = ["Abraham", "Allan", "Alsop", "Anderson", "Arnold", "Avery", "Bailey", "Baker", "Ball", "Bell", "Berry", "Black", "Blake", "Bond", "Bower", "Brown", "Buckland", "Burgess", "Butler", "Cameron", "Campbell", "Carr", "Chapman", "Churchill", "Clark", "Clarkson", "Coleman", "Cornish", "Davidson", "Davies", "Dickens", "Dowd", "Duncan", "Dyer", "Edmunds", "Ellison", "Ferguson", "Fisher", "Forsyth", "Fraser", "Gibson", "Gill", "Glover", "Graham", "Grant", "Gray", "Greene", "Hamilton", "Hardacre", "Harris", "Hart", "Hemmings", "Henderson", "Hill", "Hodges", "Howard", "Hudson", "Hughes", "Hunter", "Ince", "Jackson", "James", "Johnston", "Jones", "Kelly", "Kerr", "King", "Knox", "Lambert", "Langdon", "Lawrence", "Lee", "Lewis", "Lyman", "MacDonald", "Mackay", "Mackenzie", "MacLeod", "Manning", "Marshall", "Martin", "Mathis", "May", "McDonald", "McLean", "McGrath", "Metcalfe", "Miller", "Mills", "Mitchell", "Morgan", "Morrison", "Murray", "Nash", "Newman", "Nolan", "North", "Ogden", "Oliver", "Paige", "Parr"