login after password change

This commit is contained in:
peintnermax
2024-10-17 10:19:13 +02:00
parent 7837d61a1c
commit 7d871f3954

View File

@@ -7,6 +7,9 @@ import {
upperCaseValidator, upperCaseValidator,
} from "@/helpers/validators"; } from "@/helpers/validators";
import { setMyPassword } from "@/lib/self"; import { setMyPassword } from "@/lib/self";
import { sendPassword } from "@/lib/server/password";
import { create } from "@zitadel/client";
import { ChecksSchema } from "@zitadel/proto/zitadel/session/v2/session_service_pb";
import { PasswordComplexitySettings } from "@zitadel/proto/zitadel/settings/v2/password_settings_pb"; import { PasswordComplexitySettings } from "@zitadel/proto/zitadel/settings/v2/password_settings_pb";
import { useTranslations } from "next-intl"; import { useTranslations } from "next-intl";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
@@ -58,7 +61,7 @@ export function ChangePasswordForm({
async function submitChange(values: Inputs) { async function submitChange(values: Inputs) {
setLoading(true); setLoading(true);
const response = await setMyPassword({ const changeResponse = await setMyPassword({
sessionId: sessionId, sessionId: sessionId,
password: values.password, password: values.password,
}).catch(() => { }).catch(() => {
@@ -67,36 +70,40 @@ export function ChangePasswordForm({
setLoading(false); setLoading(false);
if (response && "error" in response) { if (changeResponse && "error" in changeResponse) {
setError(response.error); setError(changeResponse.error);
return; return;
} }
if (!response) { if (!changeResponse) {
setError("Could not change password"); setError("Could not change password");
return; return;
} }
const params = new URLSearchParams({}); const passwordResponse = await sendPassword({
loginName,
organization,
checks: create(ChecksSchema, {
password: { password: values.password },
}),
authRequestId,
}).catch(() => {
setLoading(false);
setError("Could not verify password");
return;
});
if (loginName) { setLoading(false);
params.append("loginName", loginName);
} if (
if (organization) { passwordResponse &&
params.append("organization", organization); "error" in passwordResponse &&
passwordResponse.error
) {
setError(passwordResponse.error);
} }
if (authRequestId && sessionId) { return;
if (authRequestId) {
params.append("authRequest", authRequestId);
}
return router.push(`/login?` + params);
} else {
if (authRequestId) {
params.append("authRequestId", authRequestId);
}
return router.push(`/signedin?` + params);
}
} }
const { errors } = formState; const { errors } = formState;