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

@@ -19,6 +19,7 @@ export default async function Page({
}) {
const locale = getLocale();
const t = await getTranslations({ locale, namespace: "mfa" });
const tError = await getTranslations({ locale, namespace: "error" });
const { loginName, authRequestId, organization, sessionId } = searchParams;
@@ -84,9 +85,7 @@ export default async function Page({
></UserAvatar>
)}
{!(loginName || sessionId) && (
<Alert>{t("error:unknownContext")}</Alert>
)}
{!(loginName || sessionId) && <Alert>{tError("unknownContext")}</Alert>}
{sessionFactors ? (
<ChooseSecondFactor

View File

@@ -39,6 +39,7 @@ export default async function Page({
}) {
const locale = getLocale();
const t = await getTranslations({ locale, namespace: "mfa" });
const tError = await getTranslations({ locale, namespace: "error" });
const {
loginName,
@@ -121,11 +122,9 @@ export default async function Page({
></UserAvatar>
)}
{!(loginName || sessionId) && (
<Alert>{t("error:unknownContext")}</Alert>
)}
{!(loginName || sessionId) && <Alert>{tError("unknownContext")}</Alert>}
{!valid && <Alert>{t("error.sessionExpired")}</Alert>}
{!valid && <Alert>{tError("sessionExpired")}</Alert>}
{isSessionValid(sessionWithData).valid &&
loginSettings &&

View File

@@ -15,6 +15,7 @@ export default async function Page({
}) {
const locale = getLocale();
const t = await getTranslations({ locale, namespace: "otp" });
const tError = await getTranslations({ locale, namespace: "error" });
const { loginName, authRequestId, sessionId, organization, code, submit } =
searchParams;
@@ -44,7 +45,7 @@ export default async function Page({
{!session && (
<div className="py-4">
<Alert>{t("error:unknownContext")}</Alert>
<Alert>{tError("unknownContext")}</Alert>
</div>
)}

View File

@@ -25,6 +25,7 @@ export default async function Page({
}) {
const locale = getLocale();
const t = await getTranslations({ locale, namespace: "otp" });
const tError = await getTranslations({ locale, namespace: "error" });
const { loginName, organization, sessionId, authRequestId, checkAfter } =
searchParams;
@@ -105,7 +106,7 @@ export default async function Page({
<h1>{t("set.title")}</h1>
{!session && (
<div className="py-4">
<Alert>{t("error:unknownContext")}</Alert>
<Alert>{tError("unknownContext")}</Alert>
</div>
)}

View File

@@ -14,6 +14,7 @@ export default async function Page({
}) {
const locale = getLocale();
const t = await getTranslations({ locale, namespace: "passkey" });
const tError = await getTranslations({ locale, namespace: "error" });
const { loginName, altPassword, authRequestId, organization, sessionId } =
searchParams;
@@ -51,9 +52,7 @@ export default async function Page({
)}
<p className="ztdl-p mb-6 block">{t("verify.description")}</p>
{!(loginName || sessionId) && (
<Alert>{t("error:unknownContext")}</Alert>
)}
{!(loginName || sessionId) && <Alert>{tError("unknownContext")}</Alert>}
{(loginName || sessionId) && (
<LoginPasskey

View File

@@ -13,6 +13,7 @@ export default async function Page({
}) {
const locale = getLocale();
const t = await getTranslations({ locale, namespace: "passkey" });
const tError = await getTranslations({ locale, namespace: "error" });
const { loginName, prompt, organization, authRequestId } = searchParams;
@@ -53,7 +54,7 @@ export default async function Page({
{!session && (
<div className="py-4">
<Alert>{t("error:unknownContext")}</Alert>
<Alert>{tError("unknownContext")}</Alert>
</div>
)}

View File

@@ -17,6 +17,7 @@ export default async function Page({
}) {
const locale = getLocale();
const t = await getTranslations({ locale, namespace: "password" });
const tError = await getTranslations({ locale, namespace: "error" });
const { loginName, organization, authRequestId, code } = searchParams;
@@ -46,7 +47,7 @@ export default async function Page({
{(!sessionFactors || !loginName) &&
!loginSettings?.ignoreUnknownUsernames && (
<div className="py-4">
<Alert>{t("error:unknownContext")}</Alert>
<Alert>{tError("unknownContext")}</Alert>
</div>
)}
@@ -71,7 +72,7 @@ export default async function Page({
/>
) : (
<div className="py-4">
<Alert>{t("error:failedLoading")}</Alert>
<Alert>{tError("failedLoading")}</Alert>
</div>
)}
</div>

View File

@@ -14,6 +14,7 @@ export default async function Page({
}) {
const locale = getLocale();
const t = await getTranslations({ locale, namespace: "password" });
const tError = await getTranslations({ locale, namespace: "error" });
const { loginName, organization, authRequestId, alt } = searchParams;
@@ -44,7 +45,7 @@ export default async function Page({
{(!sessionFactors || !loginName) &&
!loginSettings?.ignoreUnknownUsernames && (
<div className="py-4">
<Alert>{t("error:unknownContext")}</Alert>
<Alert>{tError("unknownContext")}</Alert>
</div>
)}

View File

@@ -17,6 +17,7 @@ export default async function Page({
}) {
const locale = getLocale();
const t = await getTranslations({ locale, namespace: "password" });
const tError = await getTranslations({ locale, namespace: "error" });
const { loginName, organization, authRequestId, code } = searchParams;
@@ -44,7 +45,7 @@ export default async function Page({
{(!sessionFactors || !loginName) &&
!loginSettings?.ignoreUnknownUsernames && (
<div className="py-4">
<Alert>{t("error:unknownContext")}</Alert>
<Alert>{tError("unknownContext")}</Alert>
</div>
)}
@@ -72,7 +73,7 @@ export default async function Page({
/>
) : (
<div className="py-4">
<Alert>{t("error:failedLoading")}</Alert>
<Alert>{tError("failedLoading")}</Alert>
</div>
)}
</div>

View File

@@ -14,6 +14,7 @@ export default async function Page({
}) {
const locale = getLocale();
const t = await getTranslations({ locale, namespace: "u2f" });
const tError = await getTranslations({ locale, namespace: "error" });
const { loginName, authRequestId, sessionId, organization } = searchParams;
@@ -50,9 +51,7 @@ export default async function Page({
)}
<p className="ztdl-p mb-6 block">{t("verify.description")}</p>
{!(loginName || sessionId) && (
<Alert>{t("error:unknownContext")}</Alert>
)}
{!(loginName || sessionId) && <Alert>{tError("unknownContext")}</Alert>}
{(loginName || sessionId) && (
<LoginPasskey

View File

@@ -13,6 +13,7 @@ export default async function Page({
}) {
const locale = getLocale();
const t = await getTranslations({ locale, namespace: "u2f" });
const tError = await getTranslations({ locale, namespace: "error" });
const { loginName, organization, authRequestId, checkAfter } = searchParams;
@@ -40,7 +41,7 @@ export default async function Page({
{!sessionFactors && (
<div className="py-4">
<Alert>{t("error:unknownContext")}</Alert>
<Alert>{tError("unknownContext")}</Alert>
</div>
)}

View File

@@ -8,6 +8,7 @@ import { getLocale, getTranslations } from "next-intl/server";
export default async function Page({ searchParams }: { searchParams: any }) {
const locale = getLocale();
const t = await getTranslations({ locale, namespace: "verify" });
const tError = await getTranslations({ locale, namespace: "error" });
const {
userId,
@@ -31,7 +32,7 @@ export default async function Page({ searchParams }: { searchParams: any }) {
{!userId && (
<div className="py-4">
<Alert>{t("error:unknownContext")}</Alert>
<Alert>{tError("unknownContext")}</Alert>
</div>
)}

View File

@@ -85,13 +85,13 @@ export function PasswordForm({
organization,
}).catch(() => {
setError("Could not reset password");
return;
});
setLoading(false);
if (response && "error" in response) {
setError(response.error);
return;
}

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,
},
},
},
{},
);