diff --git a/apps/login/src/app/(login)/verify/page.tsx b/apps/login/src/app/(login)/verify/page.tsx index 62f2284485..ca007a22f4 100644 --- a/apps/login/src/app/(login)/verify/page.tsx +++ b/apps/login/src/app/(login)/verify/page.tsx @@ -3,7 +3,7 @@ import { DynamicTheme } from "@/components/dynamic-theme"; import { UserAvatar } from "@/components/user-avatar"; import { VerifyForm } from "@/components/verify-form"; import { VerifyRedirectButton } from "@/components/verify-redirect-button"; -import { resendVerification } from "@/lib/server/verify"; +import { sendCode } from "@/lib/server/verify"; import { loadMostRecentSession } from "@/lib/session"; import { getBrandingSettings, @@ -44,7 +44,7 @@ export default async function Page(props: { searchParams: Promise }) { }); if (!skipsend && sessionFactors?.factors?.user?.id) { - await resendVerification({ + await sendCode({ userId: sessionFactors?.factors?.user?.id, isInvite: invite === "true", }).catch((error) => { @@ -54,7 +54,7 @@ export default async function Page(props: { searchParams: Promise }) { } } else if ("userId" in searchParams && userId) { if (!skipsend) { - await resendVerification({ + await sendCode({ userId, isInvite: invite === "true", }).catch((error) => { diff --git a/apps/login/src/lib/server/verify.ts b/apps/login/src/lib/server/verify.ts index 61c4bbb806..1dab0f5c90 100644 --- a/apps/login/src/lib/server/verify.ts +++ b/apps/login/src/lib/server/verify.ts @@ -7,6 +7,7 @@ import { listAuthenticationMethodTypes, resendEmailCode, resendInviteCode, + sendEmailCode, verifyEmail, verifyInviteCode, } from "@/lib/zitadel"; @@ -191,6 +192,11 @@ export async function resendVerification(command: resendVerifyEmailCommand) { : resendEmailCode(command.userId, host, command.authRequestId); } +export async function sendCode(command: resendVerifyEmailCommand) { + const host = (await headers()).get("host"); + return sendEmailCode(command.userId, host, command.authRequestId); +} + export type SendVerificationRedirectWithoutCheckCommand = { organization?: string; authRequestId?: string; diff --git a/apps/login/src/lib/zitadel.ts b/apps/login/src/lib/zitadel.ts index 8cf756807b..ac4d61816b 100644 --- a/apps/login/src/lib/zitadel.ts +++ b/apps/login/src/lib/zitadel.ts @@ -15,6 +15,7 @@ import { ResendEmailCodeRequest, ResendEmailCodeRequestSchema, RetrieveIdentityProviderIntentRequest, + SendEmailCodeRequestSchema, SetPasswordRequest, SetPasswordRequestSchema, VerifyPasskeyRegistrationRequest, @@ -273,6 +274,32 @@ export async function resendInviteCode(userId: string) { return userService.resendInviteCode({ userId }, {}); } +export async function sendEmailCode( + userId: string, + host: string | null, + authRequestId?: string, +) { + let medium = create(SendEmailCodeRequestSchema, { + userId, + }); + + if (host) { + medium = create(SendEmailCodeRequestSchema, { + ...medium, + verification: { + case: "sendCode", + value: create(SendEmailVerificationCodeSchema, { + urlTemplate: + `${host.includes("localhost") ? "http://" : "https://"}${host}/verify?code={{.Code}}&userId={{.UserID}}&organization={{.OrgID}}&invite=true` + + (authRequestId ? `&authRequestId=${authRequestId}` : ""), + }), + }, + }); + } + + return userService.sendEmailCode(medium, {}); +} + export async function createInviteCode(userId: string, host: string | null) { let medium = create(SendInviteCodeSchema, { applicationName: "Typescript Login", diff --git a/packages/zitadel-proto/package.json b/packages/zitadel-proto/package.json index 6d2df46f40..008e406a4c 100644 --- a/packages/zitadel-proto/package.json +++ b/packages/zitadel-proto/package.json @@ -11,7 +11,7 @@ ], "sideEffects": false, "scripts": { - "generate": "buf generate https://github.com/zitadel/zitadel.git --path ./proto/zitadel", + "generate": "buf generate https://github.com/zitadel/zitadel.git#branch=send-email-code --path ./proto/zitadel", "clean": "rm -rf zitadel .turbo node_modules google protoc-gen-openapiv2 validate" }, "dependencies": {