Skip to content

withPageAuthRequired regression on prop type inference when using InferGetServerSidePropsType<typeof getServerSideProps>Β #2288

@beefancohen

Description

@beefancohen

Checklist

Description

We are in the process of upgrading our sdk from v3 -> v4 in order to upgrade our next application v15 and ran into a critical type issue. It's a bit confusing because the migration docs suggest this API was removed but then seemed to have been added back in v4.9 without a ton of relevant discussion (#1790)

When using auth0.withPageAuthRequired and providing a custom getServerSideProps, props is typed as any even with InferGetServerSidePropsType<typeof getServerSideProps>.

This is a clear regression from v3.

Reproduction

  1. Use nextjs pages router
  2. Create a page component like so:
import type { InferGetServerSidePropsType } from "next";
import { auth0 } from 'src/lib/auth0';

const PageRepro = (props: InferGetServerSidePropsType<typeof getServerSideProps>) => {
   const { foo } = props; // this will be type any
    ....
}

export const getServerSideProps = auth0.withPageAuthRequired({
  async getServerSideProps(ctx) {
    if (!ctx.params?.id) {
      return { notFound: true };
    }

    const id = Number(ctx.params.id);

    return {
      props: {
        id,  // this is strongly typed as number
      },
    };
  },
});

Additional context

No response

nextjs-auth0 version

^4.9.0

Next.js version

^14.2.25

Node.js version

22.14.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions