I call a function then output it's return value in console, like so:
Index.getInitialProps = async ctx => {
const { loggedInUser } = await checkLoggedIn(ctx)
console.log('Data actually returned:')
console.log(loggedInUser)
return { loggedInUser }
}
Pretty straight forward...
The checkLoggedIn function is as follows:
export function checkLoggedIn(ctx) {
ctx.apolloClient.query({
query: GET_ME,
})
.then(({ data }) => {
console.log('Data to be returned:')
console.log(data)
return { loggedInUser: data }
})
.catch(() => { return { loggedInUser: {} } })
}
Again, pretty straight forward. This is essentially an exact copy of this example: checkLoggedIn() and getInitialProps
Now what I would expect to happen is that I should see the following in the console:
Data to be returned:
{ <DATA> }
Data actually returned:
{ loggedInUser: { <DATA> }
Instead, I see:
Data actually returned:
undefined
Data to be returned:
{ <DATA> }
Which makes zero sense as the function is returning the correct data, and it should await for this returned data before proceeding to the console.log.
Instead, it completely ignores the 'await' and doesn't even bother waiting for the function to return a value before continuing.
What is going on here?