未验证 提交 d04d9766 编写于 作者: I Ivan Kleshnin 提交者: GitHub

Improve api-routes-apollo-server-and-client-auth Example (#10358)

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
上级 9bbf31ca
......@@ -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))
......
......@@ -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>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册