Functioning login process.
This commit is contained in:
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user