Merge branch 'canary' into docs/fix-out-dated-api-key-docs-abt-rate-limits

This commit is contained in:
Maxwell
2025-11-13 18:43:09 +10:00
committed by GitHub
2 changed files with 42 additions and 1 deletions

View File

@@ -961,4 +961,42 @@ describe("oauth2", async () => {
expect(session.data?.user.email).toBe("oauth2-cookie-state@test.com");
expect(session.data?.user.name).toBe("OAuth2 Cookie State");
});
it("should await async mapProfileToUser", async () => {
const { auth } = await getTestInstance({
plugins: [
genericOAuth({
config: [
{
providerId: "test-async",
clientId: clientId,
clientSecret: clientSecret,
getUserInfo: async (_tokens) => ({
id: "test-user-id",
email: "test@example.com",
name: "Test User",
emailVerified: true,
}),
mapProfileToUser: async (
_profile,
): Promise<Record<string, any>> => {
return { customField: "async-custom-data" };
},
},
],
}),
],
});
const context = await auth.$context;
const provider = context.socialProviders.find((p) => p.id === "test-async");
const result = await provider!.getUserInfo({
accessToken: "test-access-token",
idToken: undefined,
refreshToken: undefined,
});
expect(result?.user).toHaveProperty("customField", "async-custom-data");
});
});

View File

@@ -321,6 +321,9 @@ export const genericOAuth = (options: GenericOAuthOptions) => {
if (!userInfo) {
return null;
}
const userMap = await c.mapProfileToUser?.(userInfo);
return {
user: {
id: userInfo?.id,
@@ -328,7 +331,7 @@ export const genericOAuth = (options: GenericOAuthOptions) => {
emailVerified: userInfo?.emailVerified,
image: userInfo?.image,
name: userInfo?.name,
...c.mapProfileToUser?.(userInfo),
...userMap,
},
data: userInfo,
};