mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-29 23:48:52 +00:00
feat(login): translations (#10849)
# Which Problems Are Solved Replace this example text with a concise list of problems that this PR solves. For example: - password complexity requirements have hardcoded English text - password, loginname, register and verify components have hardcoded Engilsh error messages/alerts # How the Problems Are Solved Replace this example text with a concise list of changes that this PR introduces. For example: - adds i18n for password complexity requirements - adds i18n for password, loginname, register and verify components error messages/alerts # Additional Changes - small change in code/styles for icons in PasswordComplexity to make sure that icons keep size # Additional Context N.A --------- Co-authored-by: Adam Kida <[email protected]>
This commit is contained in:
co-authored by
Adam Kida
parent
794054c075
commit
64e14de091
@@ -3,6 +3,7 @@
|
||||
import { create } from "@zitadel/client";
|
||||
import { ChecksSchema } from "@zitadel/proto/zitadel/session/v2/session_service_pb";
|
||||
import { AuthenticationMethodType } from "@zitadel/proto/zitadel/user/v2/user_service_pb";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { headers } from "next/headers";
|
||||
import { idpTypeToIdentityProviderType, idpTypeToSlug } from "../idp";
|
||||
|
||||
@@ -36,13 +37,15 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
||||
const _headers = await headers();
|
||||
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
||||
|
||||
const t = await getTranslations("loginname");
|
||||
|
||||
const loginSettingsByContext = await getLoginSettings({
|
||||
serviceUrl,
|
||||
organization: command.organization,
|
||||
});
|
||||
|
||||
if (!loginSettingsByContext) {
|
||||
return { error: "Could not get login settings" };
|
||||
return { error: t("errors.couldNotGetLoginSettings") };
|
||||
}
|
||||
|
||||
let searchUsersRequest: SearchUsersCommand = {
|
||||
@@ -60,7 +63,7 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
||||
}
|
||||
|
||||
if (!("result" in searchResult)) {
|
||||
return { error: "Could not search users" };
|
||||
return { error: t("errors.couldNotSearchUsers") };
|
||||
}
|
||||
|
||||
const { result: potentialUsers } = searchResult;
|
||||
@@ -108,7 +111,7 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
||||
});
|
||||
|
||||
if (!url) {
|
||||
return { error: "Could not start IDP flow" };
|
||||
return { error: t("errors.couldNotStartIDPFlow") };
|
||||
}
|
||||
|
||||
return { redirect: url };
|
||||
@@ -138,7 +141,7 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
||||
const idpType = idp?.type;
|
||||
|
||||
if (!idp || !idpType) {
|
||||
throw new Error("Could not find identity provider");
|
||||
throw new Error(t("errors.couldNotFindIdentityProvider"));
|
||||
}
|
||||
|
||||
const identityProviderType = idpTypeToIdentityProviderType(idpType);
|
||||
@@ -170,7 +173,7 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
||||
});
|
||||
|
||||
if (!url) {
|
||||
return { error: "Could not start IDP flow" };
|
||||
return { error: t("errors.couldNotStartIDPFlow") };
|
||||
}
|
||||
|
||||
return { redirect: url };
|
||||
@@ -178,7 +181,7 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
||||
};
|
||||
|
||||
if (potentialUsers.length > 1) {
|
||||
return { error: "More than one user found. Provide a unique identifier." };
|
||||
return { error: t("errors.moreThanOneUserFound") };
|
||||
} else if (potentialUsers.length == 1 && potentialUsers[0].userId) {
|
||||
const user = potentialUsers[0];
|
||||
const userId = potentialUsers[0].userId;
|
||||
@@ -196,15 +199,15 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
||||
// recheck login settings after user discovery, as the search might have been done without org scope
|
||||
if (userLoginSettings?.disableLoginWithEmail && userLoginSettings?.disableLoginWithPhone) {
|
||||
if (user.preferredLoginName !== concatLoginname) {
|
||||
return { error: "User not found in the system!" };
|
||||
return { error: t("errors.userNotFound") };
|
||||
}
|
||||
} else if (userLoginSettings?.disableLoginWithEmail) {
|
||||
if (user.preferredLoginName !== concatLoginname || humanUser?.phone?.phone !== command.loginName) {
|
||||
return { error: "User not found in the system!" };
|
||||
return { error: t("errors.userNotFound") };
|
||||
}
|
||||
} else if (userLoginSettings?.disableLoginWithPhone) {
|
||||
if (user.preferredLoginName !== concatLoginname || humanUser?.email?.email !== command.loginName) {
|
||||
return { error: "User not found in the system!" };
|
||||
return { error: t("errors.userNotFound") };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,18 +215,29 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
||||
user: { search: { case: "userId", value: userId } },
|
||||
});
|
||||
|
||||
const session = await createSessionAndUpdateCookie({
|
||||
const sessionOrError = await createSessionAndUpdateCookie({
|
||||
checks,
|
||||
requestId: command.requestId,
|
||||
}).catch((error) => {
|
||||
if (error?.rawMessage === "Errors.User.NotActive (SESSION-Gj4ko)") {
|
||||
return { error: t("errors.userNotActive") };
|
||||
}
|
||||
throw error;
|
||||
});
|
||||
|
||||
if ("error" in sessionOrError) {
|
||||
return sessionOrError;
|
||||
}
|
||||
|
||||
const session = sessionOrError;
|
||||
|
||||
if (!session.factors?.user?.id) {
|
||||
return { error: "Could not create session for user" };
|
||||
return { error: t("errors.couldNotCreateSession") };
|
||||
}
|
||||
|
||||
// TODO: check if handling of userstate INITIAL is needed
|
||||
if (user.state === UserState.INITIAL) {
|
||||
return { error: "Initial User not supported" };
|
||||
return { error: t("errors.initialUserNotSupported") };
|
||||
}
|
||||
|
||||
const methods = await listAuthenticationMethodTypes({
|
||||
@@ -262,7 +276,7 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
||||
}
|
||||
|
||||
return {
|
||||
error: "Username Password not allowed! Contact your administrator for more information.",
|
||||
error: t("errors.usernamePasswordNotAllowed"),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -287,7 +301,7 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
||||
case AuthenticationMethodType.PASSKEY: // AuthenticationMethodType.AUTHENTICATION_METHOD_TYPE_PASSKEY
|
||||
if (userLoginSettings?.passkeysType === PasskeysType.NOT_ALLOWED) {
|
||||
return {
|
||||
error: "Passkeys not allowed! Contact your administrator for more information.",
|
||||
error: t("errors.passkeysNotAllowed"),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -366,7 +380,7 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
||||
if (resp) {
|
||||
return resp;
|
||||
}
|
||||
return { error: "User not found in the system" };
|
||||
return { error: t("errors.userNotFound") };
|
||||
} else if (loginSettingsByContext?.allowRegister && loginSettingsByContext?.allowUsernamePassword) {
|
||||
let orgToRegisterOn: string | undefined = command.organization;
|
||||
|
||||
@@ -429,5 +443,5 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
||||
|
||||
// fallbackToPassword
|
||||
|
||||
return { error: "User not found in the system" };
|
||||
return { error: t("errors.userNotFound") };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user