fix 'me' on refresh
This commit is contained in:
parent
b468c033ca
commit
69b5aed85d
@ -37,11 +37,20 @@ export function getGetServerSideProps (query, variables = null, notFoundFunc, re
|
|||||||
return async function ({ req, query: params }) {
|
return async function ({ req, query: params }) {
|
||||||
const { nodata, ...realParams } = params
|
const { nodata, ...realParams } = params
|
||||||
const vars = { ...realParams, ...variables }
|
const vars = { ...realParams, ...variables }
|
||||||
|
const client = await getSSRApolloClient(req)
|
||||||
|
|
||||||
|
const { data: { me } } = await client.query({
|
||||||
|
query: ME_SSR
|
||||||
|
})
|
||||||
|
|
||||||
|
const price = await getPrice()
|
||||||
|
|
||||||
// we want to use client-side cache
|
// we want to use client-side cache
|
||||||
if (nodata && query) {
|
if (nodata && query) {
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
|
me,
|
||||||
|
price,
|
||||||
apollo: {
|
apollo: {
|
||||||
query: print(query),
|
query: print(query),
|
||||||
variables: vars
|
variables: vars
|
||||||
@ -56,7 +65,6 @@ export function getGetServerSideProps (query, variables = null, notFoundFunc, re
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = await getSSRApolloClient(req)
|
|
||||||
let error = null; let data = null; let props = {}
|
let error = null; let data = null; let props = {}
|
||||||
if (query) {
|
if (query) {
|
||||||
({ error, data } = await client.query({
|
({ error, data } = await client.query({
|
||||||
@ -78,12 +86,6 @@ export function getGetServerSideProps (query, variables = null, notFoundFunc, re
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data: { me } } = await client.query({
|
|
||||||
query: ME_SSR
|
|
||||||
})
|
|
||||||
|
|
||||||
const price = await getPrice()
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
...props,
|
...props,
|
||||||
|
@ -7,10 +7,10 @@ export const MeContext = React.createContext({
|
|||||||
})
|
})
|
||||||
|
|
||||||
export function MeProvider ({ me, children }) {
|
export function MeProvider ({ me, children }) {
|
||||||
const { data } = useQuery(ME, { pollInterval: 1000 })
|
const { data } = useQuery(ME, { pollInterval: 1000, fetchPolicy: 'cache-and-network' })
|
||||||
|
|
||||||
const contextValue = {
|
const contextValue = {
|
||||||
me: data ? data.me : me
|
me: data?.me || me
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user