Skip to content

Commit 175e6c1

Browse files
committed
Add loginInProgress local state
1 parent 3cb3e77 commit 175e6c1

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/lib/apollo.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { ApolloClient } from 'apollo-client'
22
import { InMemoryCache } from 'apollo-cache-inmemory'
3-
import { split } from 'apollo-link'
3+
import { ApolloLink, split } from 'apollo-link'
44
import { WebSocketLink } from 'apollo-link-ws'
55
import { createHttpLink } from 'apollo-link-http'
66
import { getMainDefinition } from 'apollo-utilities'
77
import { setContext } from 'apollo-link-context'
88
import { getAuthToken } from 'auth0-helpers'
9+
import { withClientState } from 'apollo-link-state'
910

1011
import { errorLink } from './errorLink'
1112

@@ -48,8 +49,16 @@ const networkLink = split(
4849
authedHttpLink
4950
)
5051

51-
const link = errorLink.concat(networkLink)
52-
5352
const cache = new InMemoryCache()
5453

54+
const stateLink = withClientState({
55+
cache,
56+
defaults: {
57+
loginInProgress: false
58+
},
59+
resolvers: {}
60+
})
61+
62+
const link = ApolloLink.from([errorLink, stateLink, networkLink])
63+
5564
export const apollo = new ApolloClient({ link, cache })

src/lib/auth.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ initAuthHelpers({
3030
})
3131

3232
export const login = () => {
33+
apollo.writeData({ data: { loginInProgress: true } })
34+
3335
auth0Login({
3436
onCompleted: e => {
37+
apollo.writeData({ data: { loginInProgress: false } })
38+
3539
if (e) {
3640
console.error(e)
3741
return

src/lib/withUser.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ export const USER_QUERY = gql`
1414
id
1515
}
1616
}
17+
loginInProgress @client
1718
}
1819
`
1920

2021
export const withUser = graphql(USER_QUERY, {
21-
props: ({ data: { currentUser, loading } }) => ({
22+
props: ({ data: { currentUser, loading, loginInProgress } }) => ({
2223
user: currentUser,
23-
loggingIn: loading
24+
loggingIn: loading || loginInProgress
2425
})
2526
})

0 commit comments

Comments
 (0)