use urlTemplate for emails, fix error i18n

This commit is contained in:
peintnermax
2024-10-17 16:35:30 +02:00
parent b1ad3ab374
commit e10a54d4ae
15 changed files with 47 additions and 32 deletions

View File

@@ -18,6 +18,7 @@ import {
} from "@zitadel/proto/zitadel/session/v2/session_service_pb";
import { User, UserState } from "@zitadel/proto/zitadel/user/v2/user_pb";
import { AuthenticationMethodType } from "@zitadel/proto/zitadel/user/v2/user_service_pb";
import { headers } from "next/headers";
import { redirect } from "next/navigation";
import { getSessionCookieByLoginName } from "../cookies";
@@ -27,6 +28,8 @@ type ResetPasswordCommand = {
};
export async function resetPassword(command: ResetPasswordCommand) {
const host = headers().get("host");
const users = await listUsers({
loginName: command.loginName,
organizationId: command.organization,
@@ -41,7 +44,7 @@ export async function resetPassword(command: ResetPasswordCommand) {
}
const userId = users.result[0].userId;
return passwordReset(userId);
return passwordReset(userId, host);
}
export type UpdateSessionCommand = {

View File

@@ -492,16 +492,24 @@ export function createUser(
* @param userId the id of the user where the email should be set
* @returns the newly set email
*/
export async function passwordReset(userId: string) {
export async function passwordReset(userId: string, host: string | null) {
return userService.passwordReset(
{
userId,
medium: {
case: "sendLink",
value: {
notificationType: NotificationType.Email,
},
},
medium: host
? {
case: "sendLink",
value: {
notificationType: NotificationType.Email,
urlTemplate: `https://${host}/password/set?code={{.Code}}&userId={{.UserID}}&organization={{.OrgID}}`,
},
}
: {
case: "sendLink",
value: {
notificationType: NotificationType.Email,
},
},
},
{},
);