rsnext/examples/api-routes-apollo-server-and-client-auth/pages/signout.js
Aaron Reisman a356d2f68c Add Apollo Server and Client Auth Example (#9913)
* Add Apollo Server and Client Auth Example

* Some updates

* Updated docs

Co-authored-by: Luis Alvarez D. <luis@zeit.co>
2020-01-23 14:55:45 -05:00

29 lines
607 B
JavaScript

import React from 'react'
import { useMutation } 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 router = useRouter()
const [signOut] = useMutation(SignOutMutation)
React.useEffect(() => {
if (typeof window !== 'undefined') {
signOut().then(() => {
router.push('/signin')
})
}
}, [signOut, router])
return <p>Signing out...</p>
}
export default withApollo(SignOut)