Added refresh checking logic for tokens.

This commit is contained in:
Patrick Fic
2020-01-02 09:13:55 -08:00
parent fa6a1b1eea
commit 8969108cc4
5 changed files with 63 additions and 24 deletions

View File

@@ -16,6 +16,7 @@ import { ApolloLink } from "apollo-boost";
import { ApolloProvider } from "react-apollo";
import { persistCache } from "apollo-cache-persist";
import initialState from "../graphql/initial-state";
import { shouldRefreshToken, refreshToken } from "../graphql/middleware";
class AppContainer extends Component {
state = {
@@ -71,6 +72,11 @@ class AppContainer extends Component {
const token = localStorage.getItem("token");
// return the headers to the context so httpLink can read them
if (token) {
console.log("checking if token should refresh.");
if (shouldRefreshToken) {
refreshToken();
}
return {
headers: {
...headers,