mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 07:24:51 +00:00
login after password change
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user