import { Mutation, withApollo } from 'react-apollo' import gql from 'graphql-tag' import cookie from 'cookie' import redirect from '../lib/redirect' const SIGN_IN = gql` mutation Signin($email: String!, $password: String!) { signinUser(email: { email: $email, password: $password }) { token } } ` // TODO: Find a better name for component. const SigninBox = ({ client }) => { let email, password return ( { // Store the token in cookie document.cookie = cookie.serialize('token', data.signinUser.token, { maxAge: 30 * 24 * 60 * 60 // 30 days }) // Force a reload of all the current queries now that the user is // logged in client.cache.reset().then(() => { redirect({}, '/') }) }} onError={error => { // If you want to send error to external service? console.log(error) }} > {(signinUser, { data, error }) => (
{ e.preventDefault() e.stopPropagation() signinUser({ variables: { email: email.value, password: password.value } }) email.value = password.value = '' }} > {error &&

No user found with that information.

} { email = node }} />
{ password = node }} type='password' />
)}
) } export default withApollo(SigninBox)