Use with other server side props
urgent opened this issue · 1 comments
urgent commented
next-auth requires I pass a session prop from the server on page load. Otherwise there's a delay as a call is needed to be made client side. Is it possible to provide a server variable alongside relay-nextjs?
function Home({ preloadedQuery, session }) {
...
}
export default withRelay(Home, HomeQuery, {
...
})
export async function getInitialProps(context) {
return {
props: {
session: await getSession(context),
},
};
}
rrdelaney commented
Yes, this is possible with the serverSideProps
option in the page API: https://reverecre.github.io/relay-nextjs/docs/page-api#relayoptions.
Example usage would be something like:
export default withRelay(Home, HomeQuery, {
// ...
serverSideProps: async (context) => {
const { getSession } = await import('my-auth-library');
const session = await getSession(context);
return { session };
},
})