User is in "authenticated" area of the app. There are a bunch of queries that rely on him being logged in and us having his _id
I have functions in the top component (componentDidMount) to check for the user in ApolloStore, if the user is not there, then I re-route them back to login page.
Similarly on login page, if the user exists, I re-route them into the authenticated area of the app
to logout, user clicks a "logout" button. Which, give or take, runs this code:
I always get an error about "_id" not being available before I send them back to the login page.
the error is because the server knows the user is not logged in, but the client (apollo store) doesn't. So by the time code runs in my .then() statement, I'm getting errors on the server.
If I remove the ApolloClient.resetStore(), then I get no error (but they never get re-routed to login because apollo store still thinks the user exists).
If I re-route them before the logout function runs, they would just get re-routed back into the app by the login page (which at that point assumes the user is logged in already)
If I re-route them to login prior to ApolloClient.resetStore(), the login page re-routes them back into the app because they think the user still exists.
ended up just trying to clean up my server side code more and seems to be okay. I think I need an overall revamp of my strategy beyond re-routing back and forth in componentDidMount, etc
User is in "authenticated" area of the app. There are a bunch of queries that rely on him being logged in and us having his _id
I have functions in the top component (componentDidMount) to check for the user in ApolloStore, if the user is not there, then I re-route them back to login page.
Similarly on login page, if the user exists, I re-route them into the authenticated area of the app
to logout, user clicks a "logout" button. Which, give or take, runs this code:
My problem:
I always get an error about "_id" not being available before I send them back to the login page.
the error is because the server knows the user is not logged in, but the client (apollo store) doesn't. So by the time code runs in my .then() statement, I'm getting errors on the server.
If I remove the ApolloClient.resetStore(), then I get no error (but they never get re-routed to login because apollo store still thinks the user exists).
If I re-route them before the logout function runs, they would just get re-routed back into the app by the login page (which at that point assumes the user is logged in already)
If I re-route them to login prior to ApolloClient.resetStore(), the login page re-routes them back into the app because they think the user still exists.