In progress sign in changes.
This commit is contained in:
83
client/src/App/App.js
Normal file
83
client/src/App/App.js
Normal file
@@ -0,0 +1,83 @@
|
||||
import React from "react";
|
||||
import "./App.css";
|
||||
|
||||
import { auth, createUserProfileDocument } from "../firebase/firebase.utils";
|
||||
import { gql } from "apollo-boost";
|
||||
|
||||
import HeaderAppBar from "../components/header-app-bar/header-app-bar.component";
|
||||
|
||||
const SET_CURRENT_USER = gql`
|
||||
mutation SetCurrentUser($user: User!) {
|
||||
setCurrentUser(user: $user) @client
|
||||
}
|
||||
`;
|
||||
|
||||
const GET_CURRENT_USER = gql`
|
||||
{
|
||||
currentUser @client
|
||||
}
|
||||
`;
|
||||
|
||||
class App extends React.Component {
|
||||
unsubscribeFromAuth = null;
|
||||
|
||||
componentDidMount() {
|
||||
const { setCurrentUser } = this.props;
|
||||
this.unsubscribeFromAuth = auth.onAuthStateChanged(async userAuth => {
|
||||
console.log("userAuth", userAuth);
|
||||
if (userAuth) {
|
||||
const token = await userAuth.getIdToken();
|
||||
console.log("token", token);
|
||||
const idTokenResult = await userAuth.getIdTokenResult();
|
||||
const hasuraClaim =
|
||||
idTokenResult.claims["https://hasura.io/jwt/claims"];
|
||||
|
||||
if (hasuraClaim) {
|
||||
console.log("status should be in");
|
||||
//setAuthState({ status: "in", user, token });
|
||||
} else {
|
||||
// Check if refresh is required.
|
||||
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("status should be in");
|
||||
});
|
||||
}
|
||||
} else {
|
||||
//setAuthState({ status: "out" });
|
||||
}
|
||||
|
||||
// if (userAuth) {
|
||||
// const userRef = await createUserProfileDocument(userAuth);
|
||||
|
||||
// userRef.onSnapshot(snapShot => {
|
||||
// setCurrentUser({
|
||||
// id: snapShot.id,
|
||||
// ...snapShot.data()
|
||||
// });
|
||||
// });
|
||||
// } else {
|
||||
// setCurrentUser(userAuth);
|
||||
// }
|
||||
});
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.unsubscribeFromAuth();
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<HeaderAppBar />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default App;
|
||||
Reference in New Issue
Block a user