Skip to content

Commit

Permalink
Merge pull request #325 from zitadel/buf-gen-branch
Browse files Browse the repository at this point in the history
send code on verify page visit, generate from branch
  • Loading branch information
peintnermax authored Dec 27, 2024
2 parents 478f795 + 2b43be7 commit 18f2cba
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
6 changes: 3 additions & 3 deletions apps/login/src/app/(login)/verify/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -44,7 +44,7 @@ export default async function Page(props: { searchParams: Promise<any> }) {
});

if (!skipsend && sessionFactors?.factors?.user?.id) {
await resendVerification({
await sendCode({
userId: sessionFactors?.factors?.user?.id,
isInvite: invite === "true",
}).catch((error) => {
Expand All @@ -54,7 +54,7 @@ export default async function Page(props: { searchParams: Promise<any> }) {
}
} else if ("userId" in searchParams && userId) {
if (!skipsend) {
await resendVerification({
await sendCode({
userId,
isInvite: invite === "true",
}).catch((error) => {
Expand Down
6 changes: 6 additions & 0 deletions apps/login/src/lib/server/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
listAuthenticationMethodTypes,
resendEmailCode,
resendInviteCode,
sendEmailCode,
verifyEmail,
verifyInviteCode,
} from "@/lib/zitadel";
Expand Down Expand Up @@ -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;
Expand Down
27 changes: 27 additions & 0 deletions apps/login/src/lib/zitadel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ResendEmailCodeRequest,
ResendEmailCodeRequestSchema,
RetrieveIdentityProviderIntentRequest,
SendEmailCodeRequestSchema,
SetPasswordRequest,
SetPasswordRequestSchema,
VerifyPasskeyRegistrationRequest,
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/zitadel-proto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 18f2cba

Please sign in to comment.