Skip to content

Commit

Permalink
Improve api-routes-apollo-server-and-client-auth Example (#10358)
Browse files Browse the repository at this point in the history
1. Prevent possible race conditions of cache pruning, refetching and redirects

2. Note: the original code has the following defect.

SignOut action restarts the dev server effectively resetting the memory and erasing all the "registered users" data. You have to SignUp again after SignOut. I'm not sure how
to properly fix it a.t.m
  • Loading branch information
ivan-kleshnin committed Jan 31, 2020
1 parent 9bbf31c commit d04d976
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Expand Up @@ -31,15 +31,15 @@ function SignIn() {
const passwordElement = event.currentTarget.elements.password

try {
await client.resetStore()
const { data } = await signIn({
variables: {
email: emailElement.value,
password: passwordElement.value,
},
})
client.resetStore()
if (data.signIn.user) {
router.push('/')
await router.push('/')
}
} catch (error) {
setErrorMsg(getErrorMessage(error))
Expand Down
Expand Up @@ -16,12 +16,11 @@ function SignOut() {
const [signOut] = useMutation(SignOutMutation)

React.useEffect(() => {
if (typeof window !== 'undefined') {
signOut().then(() => {
client.resetStore()
signOut().then(() => {
client.resetStore().then(() => {
router.push('/signin')
})
}
})
}, [signOut, router, client])

return <p>Signing out...</p>
Expand Down

0 comments on commit d04d976

Please sign in to comment.