express
express copied to clipboard
oidc does not exist on Request type
Issue
import { Request } from 'express'
...
export async function getServerSideProps(context: GetServerSidePropsContext & { req: Request }) {
const variable = context.req?.oidc?.user['parameter'];
}

Tried
- Upgrading to 4.18.x
- Upgrading to beta
- Restarting ts server
- re-yarn-ing
are you using next.js? if yes you cannot mix express Request type with it
@CalebJamesStevens, like @dtsuper3 said, you can't mix an express and nextjs.
If you want to have oidc
in the req
object, you will need to modify the GetServerSidePropsContext
type.
Try doing this:
- add a new
next.d.ts
file in your project and add the following code in it. - aim here is to add a new
oidc
property in it.
import type { GetServerSidePropsContext as OriginalGetServerSidePropsContext } from "next/types";
declare module "next" {
export type GetServerSidePropsContext<
Q extends ParsedUrlQuery = ParsedUrlQuery,
D extends PreviewData = PreviewData,
> = OriginalGetServerSidePropsContext<Q, D> & {
req: {
oidc: string; // use the correct type here
};
};
export type GetServerSideProps<
P extends { [key: string]: any } = { [key: string]: any },
Q extends ParsedUrlQuery = ParsedUrlQuery,
D extends PreviewData = PreviewData,
> = (context: GetServerSidePropsContext<Q, D>) => Promise<GetServerSidePropsResult<P>>;
}
export {};