mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-25 09:51:39 +00:00
send code on verify page visit, generate from branch
This commit is contained in:
@@ -3,7 +3,7 @@ import { DynamicTheme } from "@/components/dynamic-theme";
|
|||||||
import { UserAvatar } from "@/components/user-avatar";
|
import { UserAvatar } from "@/components/user-avatar";
|
||||||
import { VerifyForm } from "@/components/verify-form";
|
import { VerifyForm } from "@/components/verify-form";
|
||||||
import { VerifyRedirectButton } from "@/components/verify-redirect-button";
|
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 { loadMostRecentSession } from "@/lib/session";
|
||||||
import {
|
import {
|
||||||
getBrandingSettings,
|
getBrandingSettings,
|
||||||
@@ -44,7 +44,7 @@ export default async function Page(props: { searchParams: Promise<any> }) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!skipsend && sessionFactors?.factors?.user?.id) {
|
if (!skipsend && sessionFactors?.factors?.user?.id) {
|
||||||
await resendVerification({
|
await sendCode({
|
||||||
userId: sessionFactors?.factors?.user?.id,
|
userId: sessionFactors?.factors?.user?.id,
|
||||||
isInvite: invite === "true",
|
isInvite: invite === "true",
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
@@ -54,7 +54,7 @@ export default async function Page(props: { searchParams: Promise<any> }) {
|
|||||||
}
|
}
|
||||||
} else if ("userId" in searchParams && userId) {
|
} else if ("userId" in searchParams && userId) {
|
||||||
if (!skipsend) {
|
if (!skipsend) {
|
||||||
await resendVerification({
|
await sendCode({
|
||||||
userId,
|
userId,
|
||||||
isInvite: invite === "true",
|
isInvite: invite === "true",
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
|
@@ -7,6 +7,7 @@ import {
|
|||||||
listAuthenticationMethodTypes,
|
listAuthenticationMethodTypes,
|
||||||
resendEmailCode,
|
resendEmailCode,
|
||||||
resendInviteCode,
|
resendInviteCode,
|
||||||
|
sendEmailCode,
|
||||||
verifyEmail,
|
verifyEmail,
|
||||||
verifyInviteCode,
|
verifyInviteCode,
|
||||||
} from "@/lib/zitadel";
|
} from "@/lib/zitadel";
|
||||||
@@ -191,6 +192,11 @@ export async function resendVerification(command: resendVerifyEmailCommand) {
|
|||||||
: resendEmailCode(command.userId, host, command.authRequestId);
|
: 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 = {
|
export type SendVerificationRedirectWithoutCheckCommand = {
|
||||||
organization?: string;
|
organization?: string;
|
||||||
authRequestId?: string;
|
authRequestId?: string;
|
||||||
|
@@ -15,6 +15,7 @@ import {
|
|||||||
ResendEmailCodeRequest,
|
ResendEmailCodeRequest,
|
||||||
ResendEmailCodeRequestSchema,
|
ResendEmailCodeRequestSchema,
|
||||||
RetrieveIdentityProviderIntentRequest,
|
RetrieveIdentityProviderIntentRequest,
|
||||||
|
SendEmailCodeRequestSchema,
|
||||||
SetPasswordRequest,
|
SetPasswordRequest,
|
||||||
SetPasswordRequestSchema,
|
SetPasswordRequestSchema,
|
||||||
VerifyPasskeyRegistrationRequest,
|
VerifyPasskeyRegistrationRequest,
|
||||||
@@ -273,6 +274,32 @@ export async function resendInviteCode(userId: string) {
|
|||||||
return userService.resendInviteCode({ userId }, {});
|
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) {
|
export async function createInviteCode(userId: string, host: string | null) {
|
||||||
let medium = create(SendInviteCodeSchema, {
|
let medium = create(SendInviteCodeSchema, {
|
||||||
applicationName: "Typescript Login",
|
applicationName: "Typescript Login",
|
||||||
|
@@ -11,7 +11,7 @@
|
|||||||
],
|
],
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"scripts": {
|
"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"
|
"clean": "rm -rf zitadel .turbo node_modules google protoc-gen-openapiv2 validate"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
Reference in New Issue
Block a user