1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Minor update to with-apollo-auth (#4426)

Changes
* Update dependencies.
* Remove sending client prop to component on pages.
* Use withApollo correctly on components.
* Use `client.cache.reset()` instead of `prop.client.resetStore()`.

@adamsoffer @timneutkens
This commit is contained in:
Tage A. L. K 2018-05-21 12:13:56 +02:00 committed by Tim Neutkens
parent 57be892d02
commit 54e152b11b
5 changed files with 44 additions and 44 deletions

View file

@ -14,7 +14,7 @@ const CREATE_USER = gql`
} }
` `
const RegisterBox = (props) => { const RegisterBox = ({ client }) => {
let name, email, password let name, email, password
return ( return (
@ -25,7 +25,7 @@ const RegisterBox = (props) => {
}) })
// Force a reload of all the current queries now that the user is // Force a reload of all the current queries now that the user is
// logged in // logged in
props.client.resetStore().then(() => { client.cache.reset().then(() => {
redirect({}, '/') redirect({}, '/')
}) })
}} onError={(error) => { }} onError={(error) => {
@ -33,26 +33,26 @@ const RegisterBox = (props) => {
console.log(error) console.log(error)
}}> }}>
{(create, { data, error }) => ( {(create, { data, error }) => (
<div> <form onSubmit={e => {
<form onSubmit={e => { e.preventDefault()
e.preventDefault() e.stopPropagation()
e.stopPropagation()
create({ variables: { create({
variables: {
name: name.value, name: name.value,
email: email.value, email: email.value,
password: password.value password: password.value
}}) }
})
name.value = email.value = password.value = '' name.value = email.value = password.value = ''
}}> }}>
{ error && <p>Issue occured while registering :(</p> } {error && <p>Issue occured while registering :(</p>}
<input name='name' placeholder='Name' ref={node => { name = node }} /><br /> <input name='name' placeholder='Name' ref={node => { name = node }} /><br />
<input name='email' placeholder='Email' ref={node => { email = node }} /><br /> <input name='email' placeholder='Email' ref={node => { email = node }} /><br />
<input name='password' placeholder='Password' ref={node => { password = node }} type='password' /><br /> <input name='password' placeholder='Password' ref={node => { password = node }} type='password' /><br />
<button>Register</button> <button>Register</button>
</form> </form>
</div>
)} )}
</Mutation> </Mutation>

View file

@ -12,7 +12,7 @@ const SIGN_IN = gql`
` `
// TODO: Find a better name for component. // TODO: Find a better name for component.
const SigninBox = (props) => { const SigninBox = ({ client }) => {
let email, password let email, password
return ( return (
@ -23,7 +23,7 @@ const SigninBox = (props) => {
}) })
// Force a reload of all the current queries now that the user is // Force a reload of all the current queries now that the user is
// logged in // logged in
props.client.resetStore().then(() => { client.cache.reset().then(() => {
redirect({}, '/') redirect({}, '/')
}) })
}} onError={(error) => { }} onError={(error) => {
@ -31,24 +31,24 @@ const SigninBox = (props) => {
console.log(error) console.log(error)
}}> }}>
{(signinUser, { data, error }) => ( {(signinUser, { data, error }) => (
<div> <form onSubmit={e => {
<form onSubmit={e => { e.preventDefault()
e.preventDefault() e.stopPropagation()
e.stopPropagation()
signinUser({ variables: { signinUser({
variables: {
email: email.value, email: email.value,
password: password.value password: password.value
}}) }
})
email.value = password.value = '' email.value = password.value = ''
}}> }}>
{ error && <p>No user found with that information.</p> } {error && <p>No user found with that information.</p>}
<input name='email' placeholder='Email' ref={node => { email = node }} /><br /> <input name='email' placeholder='Email' ref={node => { email = node }} /><br />
<input name='password' placeholder='Password' ref={node => { password = node }} type='password' /><br /> <input name='password' placeholder='Password' ref={node => { password = node }} type='password' /><br />
<button>Sign in</button> <button>Sign in</button>
</form> </form>
</div>
)} )}
</Mutation> </Mutation>
) )

View file

@ -9,15 +9,15 @@
"start": "next start" "start": "next start"
}, },
"dependencies": { "dependencies": {
"apollo-boost": "^0.1.4", "apollo-boost": "^0.1.6",
"apollo-link-context": "^1.0.7", "apollo-link-context": "^1.0.8",
"cookie": "^0.3.1", "cookie": "^0.3.1",
"graphql": "^0.13.2", "graphql": "^0.13.2",
"isomorphic-unfetch": "^2.0.0", "isomorphic-unfetch": "^2.0.0",
"next": "latest", "next": "latest",
"prop-types": "^15.6.1", "prop-types": "^15.6.1",
"react": "^16.2.0", "react": "^16.3.2",
"react-apollo": "^2.1.1", "react-apollo": "^2.1.4",
"react-dom": "^16.2.0" "react-dom": "^16.3.2"
} }
} }

View file

@ -21,12 +21,12 @@ export default class CreateAccount extends React.Component {
render () { render () {
return ( return (
<div> <React.Fragment>
{/* RegisterBox handles all register logic. */} {/* RegisterBox handles all register logic. */}
<RegisterBox client={this.props.client} /> <RegisterBox />
<hr /> <hr />
Already have an account? <Link prefetch href='/signin'><a>Sign in</a></Link> Already have an account? <Link prefetch href='/signin'><a>Sign in</a></Link>
</div> </React.Fragment>
) )
} }
}; };

View file

@ -21,12 +21,12 @@ export default class Signin extends React.Component {
render () { render () {
return ( return (
<div> <React.Fragment>
{/* SigninBox handles all login logic. */} {/* SigninBox handles all login logic. */}
<SigninBox client={this.props.client} /> <SigninBox />
<hr /> <hr />
New? <Link prefetch href='/create-account'><a>Create account</a></Link> New? <Link prefetch href='/create-account'><a>Create account</a></Link>
</div> </React.Fragment>
) )
} }
}; };