Next.js
getNhostSession()
Refreshes the access token if there is any and returns the Nhost session.
@returns
Nhost session
export const getServerSideProps: GetServerSideProps = async (context) => {
const nhostSession = await getNhostSession(
{ subdomain: '<project_subdomain>', region: '<project_region>' },
context
)
return {
props: {
nhostSession
}
}
}
Parameters
params required Partial<Pick<NhostReactClientConstructorParams, “subdomain” | “region” | “authUrl” | “graphqlUrl” | “storageUrl” | “functionsUrl”>>
context required GetServerSidePropsContext<ParsedUrlQuery, PreviewData>
Next.js context
Examples
Using an arrow function
export const getServerSideProps: GetServerSideProps = async (context) => {
const nhostSession = await getNhostSession(
{ subdomain: '<project_subdomain>', region: '<project_region>' },
context
)
return {
props: {
nhostSession
}
}
}
Using a regular function
export async function getServerSideProps(context: GetServerSidePropsContext) {
// or NextPageContext
const nhostSession = await getNhostSession(
{ subdomain: '<project_subdomain>', region: '<project_region>' },
context
)
return {
props: {
nhostSession
}
}
}