Skip to content

Instantly share code, notes, and snippets.

View fredriccliver's full-sized avatar
🧭
To the north

Fredric Cliver fredriccliver

🧭
To the north
View GitHub Profile
// Transpile all code following this line with babel and use '@babel/preset-env' (aka ES6) preset.
require("@babel/register")({
presets: ["@babel/preset-env"]
});
// Import the rest of our application.
module.exports = require('./server.js')
import firebase from "@firebase/app"
import "@firebase/auth"
import "@firebase/firestore"
import express from "express"
import * as Config from "./public/config.js"
// Initialize Firebase
firebase.default.initializeApp(Config.firebaseConfig)
const firebaseConfig = {
apiKey: "...",
authDomain: "...",
databaseURL: "...",
projectId: "...",
storageBucket: "...",
messagingSenderId: "...",
appId: "...",
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
.container,
.profile-section,
.login-section {
import * as Config from "./config.js"
firebase.initializeApp(Config.firebaseConfig)
var provider = new firebase.auth.GoogleAuthProvider()
const loginButton = document.getElementById("login-button")
const logoutButton = document.getElementById("logout-button")
;(() => {
loginButton.style.display = "none"
logoutButton.style.display = "none"
{
"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017",
"watch": true
import * as functions from "firebase-functions"
import * as admin from "firebase-admin"
const serviceAccount = require("./../service-account.json")
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://[project-id].firebaseio.com"
})
...
<script src="https://www.gstatic.com/firebasejs/7.19.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.19.0/firebase-firestore.js"></script>
<script>
// Your web app's Firebase configuration
var firebaseConfig = {
...
}
// Initialize Firebase
db.collection("recipes")
.get()
.then((snapshot) => {
snapshot.forEach((element) => {
console.log(element.data())
})
})
.catch((err) => console.log(err))
const now = new Date()
const recipe = {
name: form.recipe.value,
created_at: firebase.firestore.Timestamp.fromDate(now),
}
db.collection("recipes")
.add(recipe)
.then(() => {
console.log("recipe added")