rsnext/examples/api-routes-apollo-server-and-client-auth/pages/signout.js
Willian Justen 44d74e399f
chore: Remove react redundant imports on examples (#13169)
* Remove React redundant import on `analyze-bundles` example

 Co-authored-by: Marcus Silva <mvfsillva@gmail.com>

* Remove React redundant import on `api-routes-apollo-server-and-client-auth` example

Co-authored-by: Marcus Silva <mvfsillva@gmail.com>

* Remove React redundant import on `custom-server` example

    Co-authored-by: Marcus Silva <mvfsillva@gmail.com>

* Remove React redundant import on `custom-server-actionhero` example

Co-authored-by: Marcus Silva <mvfsillva@gmail.com>

Co-authored-by: Marcus Silva <mvfsillva@gmail.com>
2020-05-22 17:37:09 +02:00

29 lines
665 B
JavaScript

import { useEffect } from 'react'
import { useMutation, useApolloClient } from '@apollo/react-hooks'
import gql from 'graphql-tag'
import { useRouter } from 'next/router'
import { withApollo } from '../apollo/client'
const SignOutMutation = gql`
mutation SignOutMutation {
signOut
}
`
function SignOut() {
const client = useApolloClient()
const router = useRouter()
const [signOut] = useMutation(SignOutMutation)
useEffect(() => {
signOut().then(() => {
client.resetStore().then(() => {
router.push('/signin')
})
})
}, [signOut, router, client])
return <p>Signing out...</p>
}
export default withApollo(SignOut)