Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix api-routes-apollo-server-and-client-auth Example #10334

Merged
merged 2 commits into from Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import Link from 'next/link'
import { withApollo } from '../apollo/client'
import gql from 'graphql-tag'
import { useMutation } from '@apollo/react-hooks'
import { useMutation, useApolloClient } from '@apollo/react-hooks'
import Field from '../components/field'
import { getErrorMessage } from '../lib/form'
import { useRouter } from 'next/router'
Expand All @@ -19,6 +19,7 @@ const SignInMutation = gql`
`

function SignIn() {
const client = useApolloClient()
const [signIn] = useMutation(SignInMutation)
const [errorMsg, setErrorMsg] = React.useState()
const router = useRouter()
Expand All @@ -36,6 +37,7 @@ function SignIn() {
password: passwordElement.value,
},
})
client.resetStore()
if (data.signIn.user) {
router.push('/')
}
Expand Down
@@ -1,6 +1,5 @@
import React from 'react'
import { useMutation } from '@apollo/react-hooks'

import { useMutation, useApolloClient } from '@apollo/react-hooks'
import gql from 'graphql-tag'
import { useRouter } from 'next/router'
import { withApollo } from '../apollo/client'
Expand All @@ -12,16 +11,18 @@ const SignOutMutation = gql`
`

function SignOut() {
const client = useApolloClient()
const router = useRouter()
const [signOut] = useMutation(SignOutMutation)

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

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