Database auth is fully fixed and functional except for outbound firebase.
This commit is contained in:
@@ -10,8 +10,8 @@ export default function Auth() {
|
||||
|
||||
useEffect(() => {
|
||||
return firebase.auth().onAuthStateChanged(async user => {
|
||||
console.log("User in App Container.js: ", user);
|
||||
if (user) {
|
||||
console.log('Current User:', user)
|
||||
const token = await user.getIdToken();
|
||||
const idTokenResult = await user.getIdTokenResult();
|
||||
const hasuraClaim =
|
||||
@@ -24,17 +24,12 @@ export default function Auth() {
|
||||
const metadataRef = firebase
|
||||
.database()
|
||||
.ref("metadata/" + user.uid + "/refreshTime");
|
||||
|
||||
metadataRef.on("value", async () => {
|
||||
// Force refresh to pick up the latest custom claims changes.
|
||||
const token = await user.getIdToken(true);
|
||||
setAuthState({ status: "in", user, token });
|
||||
});
|
||||
}
|
||||
|
||||
console.log("#####Logged In. make a gql call to upsert", user);
|
||||
|
||||
|
||||
} else {
|
||||
setAuthState({ status: "out" });
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { ApolloProvider } from "react-apollo";
|
||||
import { HttpLink } from "apollo-link-http";
|
||||
import ApolloClient from "apollo-client";
|
||||
import { InMemoryCache } from "apollo-cache-inmemory";
|
||||
import { resolvers, typeDefs } from "../graphql/resolvers";
|
||||
|
||||
//Styling imports
|
||||
import "./App.css";
|
||||
@@ -18,22 +19,18 @@ const graphqlEndpoint =
|
||||
"https://bodyshop-dev-db.herokuapp.com/v1/graphql";
|
||||
|
||||
export default function App({ authState }) {
|
||||
console.log("graphqlEndpoint", graphqlEndpoint);
|
||||
|
||||
const isIn = authState.status === "in";
|
||||
|
||||
const headers = isIn ? { Authorization: `Bearer ${authState.token}` } : {};
|
||||
|
||||
const httpLink = new HttpLink({
|
||||
uri: graphqlEndpoint,
|
||||
headers
|
||||
});
|
||||
|
||||
const client = new ApolloClient({
|
||||
link: httpLink,
|
||||
cache: new InMemoryCache()
|
||||
cache: new InMemoryCache(),
|
||||
resolvers,
|
||||
typeDefs
|
||||
});
|
||||
|
||||
client.writeData({
|
||||
data: initialState
|
||||
});
|
||||
@@ -41,7 +38,7 @@ export default function App({ authState }) {
|
||||
return (
|
||||
<ApolloProvider client={client}>
|
||||
<HeaderAppBarContainer />
|
||||
<SignIn />
|
||||
{isIn ? null : <SignIn />}
|
||||
<JobListContainer />
|
||||
</ApolloProvider>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user