️ Add support for custom claim paths (#1197)

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
Luke Vella 2024-07-05 09:03:10 +01:00 committed by GitHub
parent 1d138cb2ab
commit 104d214d2e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 90 additions and 17 deletions

View file

@ -7,7 +7,7 @@ import {
NextApiRequest,
NextApiResponse,
} from "next";
import { NextAuthOptions } from "next-auth";
import { NextAuthOptions, User } from "next-auth";
import NextAuth, {
getServerSession as getServerSessionWithOptions,
} from "next-auth/next";
@ -18,10 +18,12 @@ import GoogleProvider from "next-auth/providers/google";
import { Provider } from "next-auth/providers/index";
import { posthog } from "@/app/posthog";
import { env } from "@/env";
import { absoluteUrl } from "@/utils/absolute-url";
import { CustomPrismaAdapter } from "@/utils/auth/custom-prisma-adapter";
import { mergeGuestsIntoUser } from "@/utils/auth/merge-user";
import { emailClient } from "@/utils/emails";
import { getValueByPath } from "@/utils/get-value-by-path";
const providers: Provider[] = [
// When a user registers, we don't want to go through the email verification process
@ -128,9 +130,10 @@ if (
profile(profile) {
return {
id: profile.sub,
name: profile.name,
email: profile.email,
};
name: getValueByPath(profile, env.OIDC_NAME_CLAIM_PATH),
email: getValueByPath(profile, env.OIDC_EMAIL_CLAIM_PATH),
image: getValueByPath(profile, env.OIDC_PICTURE_CLAIM_PATH),
} as User;
},
});
}