Skip to content

Commit 0dd0d08

Browse files
committed
On login/out, refetch queries/clear store
1 parent f0026a1 commit 0dd0d08

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/lib/withAuth.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react'
22
import PropTypes from 'prop-types'
33
import wrapDisplayName from 'recompose/wrapDisplayName'
4-
import { graphql } from 'react-apollo'
4+
import { graphql, withApollo } from 'react-apollo'
5+
import { ApolloClient } from 'apollo-client'
56
import gql from 'graphql-tag'
67
import auth0 from 'auth0-js'
78
import { initAuthHelpers, login, logout } from 'auth0-helpers'
@@ -42,10 +43,9 @@ const USER_QUERY = gql`
4243
`
4344

4445
const withUser = graphql(USER_QUERY, {
45-
props: ({ ownProps, data: { currentUser, loading, refetch } }) => ({
46+
props: ({ ownProps, data: { currentUser, loading } }) => ({
4647
currentUser,
4748
loading,
48-
refetch,
4949
ownProps
5050
})
5151
})
@@ -65,15 +65,15 @@ function withAuth(BaseComponent) {
6565
login({
6666
onCompleted: (e, t) => {
6767
e && console.log(e)
68-
this.props.refetch()
68+
this.props.client.reFetchObservableQueries()
6969
this.setState({ loggingIn: false })
7070
}
7171
})
7272
}
7373

7474
logout = () => {
7575
logout()
76-
this.props.refetch()
76+
this.props.client.resetStore()
7777
}
7878

7979
render() {
@@ -100,11 +100,12 @@ function withAuth(BaseComponent) {
100100
photo: PropTypes.string.isRequired,
101101
hasPurchased: PropTypes.string
102102
}),
103-
loading: PropTypes.bool.isRequired
103+
loading: PropTypes.bool.isRequired,
104+
client: PropTypes.instanceOf(ApolloClient).isRequired
104105
}
105106

106107
WithAuthWrapper.displayName = wrapDisplayName(BaseComponent, 'withAuth')
107-
return withUser(WithAuthWrapper)
108+
return withApollo(withUser(WithAuthWrapper))
108109
}
109110

110111
export default withAuth

0 commit comments

Comments
 (0)