Skip to content

Instantly share code, notes, and snippets.

View javebratt's full-sized avatar
🏠
Working from home

Jorge Vergara javebratt

🏠
Working from home
View GitHub Profile
// Is there any performance difference on this 2 approaches:
// Injecting on the Page itself:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { AngularFire, FirebaseListObservable } from 'angularfire2';
@Component({
templateUrl: 'build/pages/home/home.html',
})
// Before: When the alert gets called it interrupts the loading component, so it causes a navigation issue:
export class LoginPage {
loginUser(){
this.submitAttempt = true;
if (!this.loginForm.valid){
console.log(this.loginForm.value);
} else {
var ngTemplate = require('../dist/plugins/ng-template').ngTemplate;
var nodeResolve = require('rollup-plugin-node-resolve');
var commonjs = require('rollup-plugin-commonjs');
// https://github.com/rollup/rollup/wiki/JavaScript-API
module.exports = {
/**
* entry: The bundle's starting point. This file will
* be included, along with the minimum necessary code
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from 'ionic-native';
import { HomePage } from '../pages/home/home';
import { LoginPage } from '../pages/login/login';
import firebase from 'firebase';
@javebratt
javebratt / firebase-storage.ts
Created December 26, 2016 15:20
Quick example of uploading and retrieving images from Firebase storage.
// You create a reference for the picture:
this.profilePictureRef.child(newGuest.key).child('profilePicture.png')
// Then you upload it:
.putString(guestPicture, 'base64', {contentType: 'image/png'})
// Since it returns a promise, you save the downloadURL somewhere to use later:
.then((savedPicture) => {
this.eventList.child(eventId).child('guestList').child(newGuest.key).child('profilePicture')
.set(savedPicture.downloadURL);
// You can create a function in your authentication provider that resolves the value of admin:
isAsdmin(): Promise<any> {
return new Promise( (resolve, reject ) => {
firebase.database().ref(`userProfile/${userId}/admin`).once('value', adminSnapshot => {
resolve(adminSnapshot.val());
});
});
}
// FUNCTION 1
createEvent(eventName: string, other_params, eventMainPicture = null): any {
return this.eventList.push({
name: eventName,
... // All the other information you're adding.
...
...
}).then( newEvent => {
// When the event is created we pass in the base64 string that represents the picture to the
// The pictures I'm guessing are in Firebase Storage, but they need to be linked (through the download URL) to the database,
// so something like:
userProfile: {
user1: {
name: "Jorge",
profilePicture: "https://link_to_picture"
}
}
import { Injectable } from '@angular/core';
import firebase from 'firebase';
@Injectable()
export class ProfileProvider {
public userProfileRef;
constructor() {
this.userProfileRef = firebase.database().ref('/userProfile');
}
firebase.auth().onAuthStateChange( user => {
if (!user){
// No user, send to login.
} else {
// There is a user, check for email verification.
if (user.emailVerified) {
// Email verified, do your thing.
} else {
// No verification yet
}