Functioning login process.
This commit is contained in:
12
.vscode/launch.json
vendored
Normal file
12
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Chrome",
|
||||
"type": "chrome",
|
||||
"request": "launch",
|
||||
"url": "http://localhost:3000",
|
||||
"webRoot": "${workspaceRoot}/src"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
"private": true,
|
||||
"license": "UNLICENSED",
|
||||
"dependencies": {
|
||||
"@apollo/react-hooks": "^3.1.3",
|
||||
"antd": "^3.26.0",
|
||||
"apollo-boost": "^0.4.4",
|
||||
"dotenv": "^8.2.0",
|
||||
|
||||
@@ -4,19 +4,60 @@ import React, { useState, useEffect } from "react";
|
||||
import firebase from "../firebase/firebase.utils";
|
||||
import App from "./App";
|
||||
import { Spin } from "antd";
|
||||
import { gql } from "apollo-boost";
|
||||
import { useMutation } from "@apollo/react-hooks";
|
||||
import { HttpLink } from "apollo-link-http";
|
||||
import ApolloClient from "apollo-client";
|
||||
import { InMemoryCache } from "apollo-cache-inmemory";
|
||||
|
||||
//import gql from "graphql-tag";
|
||||
|
||||
// on_conflict: { constraint: users_pkey, update_columns: [authid] }
|
||||
|
||||
const UPSERT_USER = gql`
|
||||
mutation upsert_user($authEmail: String!, $authToken: String!) {
|
||||
insert_users(
|
||||
objects: [{ email: $authEmail, authid: $authToken }]
|
||||
on_conflict: { constraint: users_pkey, update_columns: [authid] }
|
||||
) {
|
||||
returning {
|
||||
authid
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const client = new ApolloClient({
|
||||
link: new HttpLink({
|
||||
uri: process.env.REACT_APP_GRAPHQL_ENDPOINT
|
||||
}),
|
||||
cache: new InMemoryCache()
|
||||
});
|
||||
|
||||
export default function Auth() {
|
||||
const [authState, setAuthState] = useState({ status: "loading" });
|
||||
// const [upsertUser] = useMutation(UPSERT_USER, {
|
||||
// client
|
||||
// });
|
||||
|
||||
useEffect(() => {
|
||||
return firebase.auth().onAuthStateChanged(async user => {
|
||||
if (user) {
|
||||
console.log('Current User:', user)
|
||||
console.log("Current User:", user);
|
||||
|
||||
client
|
||||
.mutate({
|
||||
mutation: UPSERT_USER,
|
||||
variables: { authEmail: user.email, authToken: user.uid }
|
||||
})
|
||||
.then(r => console.log(r))
|
||||
.catch(error => console.log("ERROR!!!!", error));
|
||||
|
||||
const token = await user.getIdToken();
|
||||
const idTokenResult = await user.getIdTokenResult();
|
||||
const hasuraClaim =
|
||||
idTokenResult.claims["https://hasura.io/jwt/claims"];
|
||||
|
||||
console.log("idTokenResult", idTokenResult);
|
||||
if (hasuraClaim) {
|
||||
setAuthState({ status: "in", user, token });
|
||||
} else {
|
||||
|
||||
@@ -14,9 +14,7 @@ import initialState from "../graphql/initial-state";
|
||||
import JobListContainer from "../components/job-list/job-list.container";
|
||||
|
||||
//Todo: Issue with this line. Not sure why.
|
||||
const graphqlEndpoint =
|
||||
process.env.REACT_APP_GRAPHQL_ENDPOINT ||
|
||||
"https://bodyshop-dev-db.herokuapp.com/v1/graphql";
|
||||
const graphqlEndpoint = process.env.REACT_APP_GRAPHQL_ENDPOINT;
|
||||
|
||||
export default function App({ authState }) {
|
||||
const isIn = authState.status === "in";
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
const functions = require("firebase-functions");
|
||||
const admin = require("firebase-admin");
|
||||
admin.initializeApp(functions.config().firebase);
|
||||
const fetch = require("node-fetch");
|
||||
|
||||
//Todo: Move this to an environment parameter.
|
||||
const GRAPHQL_ENDPOINT = functions.config().auth.graphql_endpoint;
|
||||
@@ -50,22 +49,19 @@ exports.processSignUp = functions.auth.user().onCreate(user => {
|
||||
}
|
||||
};
|
||||
}
|
||||
//update the AuthId in the graphql server.
|
||||
fetch(GRAPHQL_ENDPOINT, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"x-hasura-admin-secret": HASURA_SECRET_ADMIN_KEY
|
||||
},
|
||||
body: JSON.stringify({
|
||||
query: UPSERT_USER,
|
||||
variables: { authEmail: user.email, authToken: user.uid }
|
||||
})
|
||||
});
|
||||
// .then(r => r.json())
|
||||
// .then(data => {
|
||||
// console.log("data returned:", data);
|
||||
|
||||
//Removed for now - outbound connections are not free on firebase.
|
||||
// fetch(GRAPHQL_ENDPOINT, {
|
||||
// method: "POST",
|
||||
// headers: {
|
||||
// "Content-Type": "application/json",
|
||||
// Accept: "application/json",
|
||||
// "x-hasura-admin-secret": HASURA_SECRET_ADMIN_KEY
|
||||
// },
|
||||
// body: JSON.stringify({
|
||||
// query: UPSERT_USER,
|
||||
// variables: { authEmail: user.email, authToken: user.uid }
|
||||
// })
|
||||
// });
|
||||
|
||||
// Set custom user claims on this newly created user.
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
- args:
|
||||
role: anonymous
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: drop_insert_permission
|
||||
@@ -0,0 +1,18 @@
|
||||
- args:
|
||||
permission:
|
||||
allow_upsert: true
|
||||
check: {}
|
||||
columns:
|
||||
- authid
|
||||
- created_at
|
||||
- email
|
||||
- updated_at
|
||||
localPresets:
|
||||
- key: ""
|
||||
value: ""
|
||||
set: {}
|
||||
role: anonymous
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: create_insert_permission
|
||||
@@ -0,0 +1,19 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: drop_update_permission
|
||||
- args:
|
||||
permission:
|
||||
columns: []
|
||||
filter: {}
|
||||
localPresets:
|
||||
- key: ""
|
||||
value: ""
|
||||
set: {}
|
||||
role: user
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: create_update_permission
|
||||
@@ -0,0 +1,23 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: drop_update_permission
|
||||
- args:
|
||||
permission:
|
||||
columns:
|
||||
- email
|
||||
- authid
|
||||
- created_at
|
||||
- updated_at
|
||||
filter: {}
|
||||
localPresets:
|
||||
- key: ""
|
||||
value: ""
|
||||
set: {}
|
||||
role: user
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: create_update_permission
|
||||
@@ -0,0 +1,19 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: drop_select_permission
|
||||
- args:
|
||||
permission:
|
||||
allow_aggregations: false
|
||||
columns:
|
||||
- authid
|
||||
- email
|
||||
computed_fields: []
|
||||
filter: {}
|
||||
role: user
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: create_select_permission
|
||||
@@ -0,0 +1,21 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: drop_select_permission
|
||||
- args:
|
||||
permission:
|
||||
allow_aggregations: false
|
||||
columns:
|
||||
- authid
|
||||
- email
|
||||
- created_at
|
||||
- updated_at
|
||||
computed_fields: []
|
||||
filter: {}
|
||||
role: user
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: create_select_permission
|
||||
@@ -0,0 +1,6 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: drop_insert_permission
|
||||
@@ -0,0 +1,14 @@
|
||||
- args:
|
||||
permission:
|
||||
allow_upsert: true
|
||||
check: {}
|
||||
columns: []
|
||||
localPresets:
|
||||
- key: ""
|
||||
value: ""
|
||||
set: {}
|
||||
role: user
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: create_insert_permission
|
||||
@@ -0,0 +1,19 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: drop_insert_permission
|
||||
- args:
|
||||
permission:
|
||||
check: {}
|
||||
columns: []
|
||||
localPresets:
|
||||
- key: ""
|
||||
value: ""
|
||||
set: {}
|
||||
role: user
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: create_insert_permission
|
||||
@@ -0,0 +1,23 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: drop_insert_permission
|
||||
- args:
|
||||
permission:
|
||||
check: {}
|
||||
columns:
|
||||
- authid
|
||||
- email
|
||||
- created_at
|
||||
- updated_at
|
||||
localPresets:
|
||||
- key: ""
|
||||
value: ""
|
||||
set: {}
|
||||
role: user
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: create_insert_permission
|
||||
@@ -0,0 +1,6 @@
|
||||
- args:
|
||||
role: anonymous
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: drop_update_permission
|
||||
@@ -0,0 +1,13 @@
|
||||
- args:
|
||||
permission:
|
||||
columns: []
|
||||
filter: {}
|
||||
localPresets:
|
||||
- key: ""
|
||||
value: ""
|
||||
set: {}
|
||||
role: anonymous
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: create_update_permission
|
||||
@@ -0,0 +1,6 @@
|
||||
- args:
|
||||
role: anonymous
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: drop_select_permission
|
||||
@@ -0,0 +1,11 @@
|
||||
- args:
|
||||
permission:
|
||||
allow_aggregations: false
|
||||
columns: []
|
||||
filter: {}
|
||||
limit: null
|
||||
role: anonymous
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: create_select_permission
|
||||
@@ -0,0 +1,17 @@
|
||||
- args:
|
||||
role: anonymous
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: drop_select_permission
|
||||
- args:
|
||||
permission:
|
||||
allow_aggregations: false
|
||||
columns: []
|
||||
computed_fields: []
|
||||
filter: {}
|
||||
role: anonymous
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: create_select_permission
|
||||
@@ -0,0 +1,21 @@
|
||||
- args:
|
||||
role: anonymous
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: drop_select_permission
|
||||
- args:
|
||||
permission:
|
||||
allow_aggregations: false
|
||||
columns:
|
||||
- authid
|
||||
- email
|
||||
- created_at
|
||||
- updated_at
|
||||
computed_fields: []
|
||||
filter: {}
|
||||
role: anonymous
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: create_select_permission
|
||||
@@ -0,0 +1,19 @@
|
||||
- args:
|
||||
role: anonymous
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: drop_update_permission
|
||||
- args:
|
||||
permission:
|
||||
columns: []
|
||||
filter: {}
|
||||
localPresets:
|
||||
- key: ""
|
||||
value: ""
|
||||
set: {}
|
||||
role: anonymous
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: create_update_permission
|
||||
@@ -0,0 +1,23 @@
|
||||
- args:
|
||||
role: anonymous
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: drop_update_permission
|
||||
- args:
|
||||
permission:
|
||||
columns:
|
||||
- authid
|
||||
- email
|
||||
- created_at
|
||||
- updated_at
|
||||
filter: {}
|
||||
localPresets:
|
||||
- key: ""
|
||||
value: ""
|
||||
set: {}
|
||||
role: anonymous
|
||||
table:
|
||||
name: users
|
||||
schema: public
|
||||
type: create_update_permission
|
||||
Reference in New Issue
Block a user