KindeK
Kinde2y ago
5 replies
moroshko

Extending KindeIdToken type to include the `organizations` claim

I added an organizations claim to the id token and would like TypeScript to know about it so I could do:
import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server";
const { getIdToken } = getKindeServerSession();
const idToken = await getIdToken();
console.log(idToken.organizations); // currently TypeScript says: Property organizations does not exist on type KindeIdToken.

I tried to add the following in app/lib/types.ts:
declare global {
  interface KindeIdToken {
    organizations?: Array<{
      id: string;
      name: string;
    }>;
  }
}

but this doesn't help.
My tsconfig.json includes this types.ts:
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],

Any ideas?
Screenshot_2024-04-28_at_3.49.43_PM.png
Was this page helpful?