This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE "public"."loved_language" ( | |
"name" text NOT NULL, | |
"user_id" text NOT NULL, | |
CONSTRAINT loved_language_pkey PRIMARY KEY (name, user_id), | |
CONSTRAINT loved_language_programming_language_fky FOREIGN KEY (name) REFERENCES programming_language(name), | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const functions = require("firebase-functions"); | |
const admin = require("firebase-admin"); | |
admin.initializeApp(functions.config().firebase); | |
// On sign up. | |
exports.processSignUp = functions.auth.user().onCreate(user => { | |
const customClaims = { | |
"https://hasura.io/jwt/claims": { | |
"x-hasura-default-role": "user", | |
"x-hasura-allowed-roles": ["user"], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import firebase from "firebase/app"; | |
import "firebase/auth"; | |
import "firebase/database"; | |
import React, { useState, useEffect } from "react"; | |
import App from "./App"; | |
const provider = new firebase.auth.GoogleAuthProvider(); | |
// Find these options in your Firebase console | |
firebase.initializeApp({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { InMemoryCache } from "apollo-cache-inmemory"; | |
import ApolloClient from "apollo-client"; | |
import { split } from "apollo-link"; | |
import { HttpLink } from "apollo-link-http"; | |
import { WebSocketLink } from "apollo-link-ws"; | |
import { getMainDefinition } from "apollo-utilities"; | |
import gql from "graphql-tag"; | |
import React from "react"; | |
import { ApolloProvider, Mutation, Subscription } from "react-apollo"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const functions = require("firebase-functions"); | |
const admin = require("firebase-admin"); | |
const request = require("graphql-request"); | |
const client = new request.GraphQLClient('<your-graphql-endpoint>', { | |
headers: { | |
"content-type": "application/json", | |
"x-hasura-admin-secret": "<your-admin-secret>" | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// REGISTER USER WITH REQUIRED CUSTOM CLAIMS | |
exports.registerUser = functions.https.onCall(async (data, context) => { | |
const email = data.email; | |
const password = data.password; | |
const displayName = data.displayName; | |
if (email == null || password == null || displayName == null) { | |
throw new functions.https.HttpsError('signup-failed', 'missing information'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// REGISTER USER WITH REQUIRED CUSTOM CLAIMS | |
exports.registerUser = functions.https.onCall(async (data, context) => { | |
const email = data.email; | |
const password = data.password; | |
const displayName = data.displayName; | |
if (email == null || password == null || displayName == null) { | |
throw new functions.https.HttpsError('signup-failed', 'missing information'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SYNC WITH HASURA ON USER CREATE | |
exports.processSignUp = functions.auth.user().onCreate(async user => { | |
const id = user.uid; | |
const email = user.email; | |
const name = user.displayName || "No Name"; | |
const mutation = `mutation($id: String!, $email: String, $name: String) { | |
insert_users(objects: [{ | |
id: $id, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SYNC WITH HASURA ON USER DELETE | |
exports.processDelete = functions.auth.user().onDelete(async (user) => { | |
const mutation = `mutation($id: String!) { | |
delete_users(where: {id: {_eq: $id}}) { | |
affected_rows | |
} | |
}`; | |
const id = user.uid; | |
try { | |
const data = await client.request(mutation, { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// INCREMENT USER SCORE IF THE ANSWER IS CORRECT | |
exports.checkAnswer = functions.https.onRequest( async (request, response) => { | |
const answerID = request.body.event.data.new.answer_id; | |
const userID = request.body.event.data.new.user_id; | |
const answerQuery = ` | |
queryAnswer($answerID: uuid!) { | |
question_answers(where: {id: {_eq: $answerID}}) { | |
is_correct | |
} |
OlderNewer