mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-25 22:08:46 +00:00
fix(login): correctly redirect to /password when ignoreUnknownUsername is set (#11130)
Closes #11006 # Which Problems Are Solved This PR addresses an issue where the ignoreUnknownUsernames setting was not being respected in certain scenarios during the login flow. Specifically: - When a user was found but rejected due to login settings (e.g., disableLoginWithEmail), the system would return a "User not found" error instead of redirecting to the password page as dictated by ignoreUnknownUsernames. - When a user was not found, and the flow fell through the registration checks (e.g., IDP redirect failed), it would also return "User not found" without checking ignoreUnknownUsernames. # How the Problems Are Solved - Introduced a helper function `handleUserNotFound` in `apps/login/src/lib/server/loginname.ts` to centralize the logic for checking ignoreUnknownUsernames and redirecting to the password page. - Updated the user validation logic to call handleUserNotFound when a user is found but rejected by policy. - Updated the registration fallback logic to call handleUserNotFound instead of directly returning an error. - Added new test cases in `apps/login/src/lib/server/loginname.test.ts` to verify the fix and ensure no regressions. # Additional Changes - Fixed inconsistency in translation files --------- Co-authored-by: Livio Spring <[email protected]>
This commit is contained in:
co-authored by
Livio Spring
parent
e72203ca6d
commit
26f8238499
@@ -32,7 +32,9 @@ export async function registerUser(command: RegisterUserCommand) {
|
||||
const _headers = await headers();
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
const addResponse = await addHumanUser({ serviceConfig, email: command.email,
|
||||
const addResponse = await addHumanUser({
|
||||
serviceConfig,
|
||||
email: command.email,
|
||||
firstName: command.firstName,
|
||||
lastName: command.lastName,
|
||||
password: command.password ? command.password : undefined,
|
||||
@@ -43,8 +45,7 @@ export async function registerUser(command: RegisterUserCommand) {
|
||||
return { error: t("errors.couldNotCreateUser") };
|
||||
}
|
||||
|
||||
const loginSettings = await getLoginSettings({ serviceConfig, organization: command.organization,
|
||||
});
|
||||
const loginSettings = await getLoginSettings({ serviceConfig, organization: command.organization });
|
||||
|
||||
let checkPayload: any = {
|
||||
user: { search: { case: "userId", value: addResponse.userId } },
|
||||
@@ -59,11 +60,12 @@ export async function registerUser(command: RegisterUserCommand) {
|
||||
|
||||
const checks = create(ChecksSchema, checkPayload);
|
||||
|
||||
const session = await createSessionAndUpdateCookie({
|
||||
const result = await createSessionAndUpdateCookie({
|
||||
checks,
|
||||
requestId: command.requestId,
|
||||
lifetime: command.password ? loginSettings?.passwordCheckLifetime : undefined,
|
||||
});
|
||||
const session = result.session;
|
||||
|
||||
if (!session || !session.factors?.user) {
|
||||
return { error: t("errors.couldNotCreateSession") };
|
||||
@@ -96,8 +98,7 @@ export async function registerUser(command: RegisterUserCommand) {
|
||||
|
||||
return { redirect: "/passkey/set?" + params };
|
||||
} else {
|
||||
const userResponse = await getUserByID({ serviceConfig, userId: session?.factors?.user?.id,
|
||||
});
|
||||
const userResponse = await getUserByID({ serviceConfig, userId: session?.factors?.user?.id });
|
||||
|
||||
if (!userResponse.user) {
|
||||
return { error: t("errors.userNotFound") };
|
||||
@@ -158,7 +159,9 @@ export async function registerUserAndLinkToIDP(command: RegisterUserAndLinkToIDP
|
||||
const _headers = await headers();
|
||||
const { serviceConfig } = getServiceConfig(_headers);
|
||||
|
||||
const addUserResponse = await addHumanUser({ serviceConfig, email: command.email,
|
||||
const addUserResponse = await addHumanUser({
|
||||
serviceConfig,
|
||||
email: command.email,
|
||||
firstName: command.firstName,
|
||||
lastName: command.lastName,
|
||||
organization: command.organization,
|
||||
@@ -168,10 +171,11 @@ export async function registerUserAndLinkToIDP(command: RegisterUserAndLinkToIDP
|
||||
return { error: t("errors.couldNotCreateUser") };
|
||||
}
|
||||
|
||||
const loginSettings = await getLoginSettings({ serviceConfig, organization: command.organization,
|
||||
});
|
||||
const loginSettings = await getLoginSettings({ serviceConfig, organization: command.organization });
|
||||
|
||||
const idpLink = await addIDPLink({ serviceConfig, idp: {
|
||||
const idpLink = await addIDPLink({
|
||||
serviceConfig,
|
||||
idp: {
|
||||
id: command.idpId,
|
||||
userId: command.idpUserId,
|
||||
userName: command.idpUserName,
|
||||
@@ -215,8 +219,7 @@ export async function registerUserAndLinkToIDP(command: RegisterUserAndLinkToIDP
|
||||
// check if user has MFA methods
|
||||
let authMethods;
|
||||
if (session.factors?.user?.id) {
|
||||
const response = await listAuthenticationMethodTypes({ serviceConfig, userId: session.factors.user.id,
|
||||
});
|
||||
const response = await listAuthenticationMethodTypes({ serviceConfig, userId: session.factors.user.id });
|
||||
if (response.authMethodTypes && response.authMethodTypes.length) {
|
||||
authMethods = response.authMethodTypes;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user