Skip to content

oidc does not exist on Request type #5170

Description

@CalebJamesStevens

Issue

import { Request } from 'express'

...

export async function getServerSideProps(context: GetServerSidePropsContext & { req: Request }) {
  const variable = context.req?.oidc?.user['parameter'];
}

Screenshot 2023-04-21 at 11 52 07 AM

Tried

  • Upgrading to 4.18.x
  • Upgrading to beta
  • Restarting ts server
  • re-yarn-ing

Activity

  1. dtsuper3 commented on Apr 27, 2023

    @dtsuper3

    are you using next.js? if yes you cannot mix express Request type with it

  2. Aakash1103Jha commented on Apr 28, 2023

    @Aakash1103Jha

    @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 {};
  3. converted this issue into a discussion #5897 on Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions