Skip to content

Commit

Permalink
Cleanup comments in AuthProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
dac09 committed Jan 30, 2024
1 parent 9182742 commit 20b18d8
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions packages/auth/src/AuthProvider/AuthProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,11 @@ export function createAuthProvider<
// Whenever the authImplementation is ready to go, restore auth and reauthenticate
useEffect(() => {
async function doRestoreState() {
// @MARK: this is where we fetch currentUser from graphql again
// because without SSR, initial state doesn't exist
// what we want to do here is to conditionally call reauthenticate
// so that the restoreAuthState comes from the injected state

// the problem is that reauthenticate does both getCurrentUser and udpate the auth state
await authImplementation.restoreAuthState?.()

// If the inital state didn't come from the server (or was restored before)
// reauthenticate will make an API call to the middleware to receive the current user
// (instead of called the graphql endpoint with currentUser)
// @MARK(SSR-Auth): Conditionally call reauth, because initial state should come from server (on SSR)
// If the inital state didn't come from the server - or was restored already -
// reauthenticate will make an call to receive the current user from the server
if (!serverAuthState) {
reauthenticate()
}
Expand Down

0 comments on commit 20b18d8

Please sign in to comment.