Options
All
  • Public
  • Public/Protected
  • All
Menu

Module helpers/get-server-side-props-wrapper

Index

Server Type aliases

Server Type aliases

GetServerSidePropsWrapper

GetServerSidePropsWrapper<P, Q>: (getServerSideProps: GetServerSideProps<P, Q>) => GetServerSideProps<P, Q>

If you're using >=Next 12 and getSession or getAccessToken without withPageAuthRequired, because you don't want to require authentication on your route, you might get a warning/error: "You should not access 'res' after getServerSideProps resolves". You can work around this by wrapping your getServerSideProps in getServerSidePropsWrapper, this ensures that the code that accesses res will run within the lifecycle of getServerSideProps, avoiding the warning/error eg:

NOTE: you do not need to do this if you're already using WithPageAuthRequired

// pages/protected-page.js
import { withPageAuthRequired } from '@auth0/nextjs-auth0';

export default function ProtectedPage() {
  return <div>Protected content</div>;
}

export const getServerSideProps = getServerSidePropsWrapper(async (ctx) => {
  const session = getSession(ctx.req, ctx.res);
  if (session) {
    // Use is authenticated
  } else {
    // User is not authenticated
  }
});

Type parameters

  • P = any

  • Q: ParsedUrlQuery = ParsedUrlQuery

Type declaration

    • (getServerSideProps: GetServerSideProps<P, Q>): GetServerSideProps<P, Q>
    • Parameters

      • getServerSideProps: GetServerSideProps<P, Q>

      Returns GetServerSideProps<P, Q>