mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-24 05:38:46 +00:00
chore: standardised the eslint config structure accross the project (#11814)
This commit is contained in:
@@ -1,79 +0,0 @@
|
||||
module.exports = {
|
||||
parser: "@typescript-eslint/parser",
|
||||
extends: ["next", "prettier"],
|
||||
plugins: ["@typescript-eslint", "import"],
|
||||
rules: {
|
||||
"import/first": "error",
|
||||
"@next/next/no-html-link-for-pages": "off",
|
||||
"@next/next/no-img-element": "off",
|
||||
"react/no-unescaped-entities": "off",
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": ["error", {
|
||||
argsIgnorePattern: "^_" ,
|
||||
varsIgnorePattern: "^_" ,
|
||||
}],
|
||||
"no-undef": "off",
|
||||
"no-restricted-imports": ["error", {
|
||||
"paths": [{
|
||||
"name": "next/image",
|
||||
"message": "Use of next/image is forbidden. Use regular <img> elements instead."
|
||||
}]
|
||||
}],
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaVersion: "latest",
|
||||
sourceType: "module",
|
||||
ecmaFeatures: {
|
||||
jsx: true,
|
||||
},
|
||||
project: "./tsconfig.json",
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
// Server components and server actions: must use logger, not console.*
|
||||
// Files in src/lib/server/*, src/app/**/route.ts, src/middleware.ts, and files with "use server"
|
||||
files: [
|
||||
"src/lib/server/**/*.ts",
|
||||
"src/app/**/route.ts",
|
||||
"src/middleware.ts",
|
||||
"src/lib/cookies.ts",
|
||||
],
|
||||
rules: {
|
||||
"no-console": "warn",
|
||||
},
|
||||
},
|
||||
{
|
||||
// instrumentation.ts uses console.log during OTEL initialization (before logger is available)
|
||||
files: ["src/instrumentation.ts"],
|
||||
rules: {
|
||||
"no-console": "off",
|
||||
},
|
||||
},
|
||||
{
|
||||
// Client components: logger import is forbidden (enforced by server-only at build time)
|
||||
// This override documents the expectation for client components
|
||||
files: ["src/components/**/*.tsx"],
|
||||
rules: {
|
||||
"no-restricted-imports": ["error", {
|
||||
"paths": [
|
||||
{
|
||||
"name": "next/image",
|
||||
"message": "Use of next/image is forbidden. Use regular <img> elements instead."
|
||||
},
|
||||
{
|
||||
"name": "@/lib/logger",
|
||||
"message": "Cannot import logger in client components. Use console.* instead. The logger uses 'server-only' and will fail at build time."
|
||||
}
|
||||
]
|
||||
}],
|
||||
},
|
||||
},
|
||||
{
|
||||
// Test files: allow console.*
|
||||
files: ["**/*.test.ts", "**/*.test.tsx", "**/*.spec.ts", "**/*.spec.tsx", "**/tests/**/*"],
|
||||
rules: {
|
||||
"no-console": "off",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -1,10 +0,0 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
// Use basic ESLint config since the login app has its own detailed config
|
||||
extends: ["eslint:recommended"],
|
||||
settings: {
|
||||
next: {
|
||||
rootDir: ["apps/*/"],
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
import js from "@eslint/js";
|
||||
import tsPlugin from "@typescript-eslint/eslint-plugin";
|
||||
import tsParser from "@typescript-eslint/parser";
|
||||
import prettierConfig from "eslint-config-prettier/flat";
|
||||
|
||||
export default [
|
||||
{ ignores: ["node_modules/**"] },
|
||||
js.configs.recommended,
|
||||
{
|
||||
files: ["**/*.ts"],
|
||||
plugins: {
|
||||
"@typescript-eslint": tsPlugin,
|
||||
},
|
||||
languageOptions: {
|
||||
parser: tsParser,
|
||||
ecmaVersion: "latest",
|
||||
sourceType: "module",
|
||||
},
|
||||
rules: {
|
||||
...tsPlugin.configs.recommended.rules,
|
||||
"no-unused-vars": "off",
|
||||
"no-undef": "off",
|
||||
"@typescript-eslint/no-unused-vars": [
|
||||
"error",
|
||||
{ argsIgnorePattern: "^_" },
|
||||
],
|
||||
},
|
||||
},
|
||||
prettierConfig,
|
||||
];
|
||||
@@ -0,0 +1,149 @@
|
||||
import js from "@eslint/js";
|
||||
import nextPlugin from "@next/eslint-plugin-next";
|
||||
import tsPlugin from "@typescript-eslint/eslint-plugin";
|
||||
import tsParser from "@typescript-eslint/parser";
|
||||
import prettierConfig from "eslint-config-prettier/flat";
|
||||
import importPlugin from "eslint-plugin-import";
|
||||
import reactHooksPlugin from "eslint-plugin-react-hooks";
|
||||
import globals from "globals";
|
||||
|
||||
export default [
|
||||
{
|
||||
ignores: [
|
||||
"node_modules/**",
|
||||
".next/**",
|
||||
"dockerized/**",
|
||||
"cypress/**",
|
||||
"acceptance/**",
|
||||
"integration/**",
|
||||
"vitest.config*.ts",
|
||||
"next-env.d.ts",
|
||||
],
|
||||
},
|
||||
js.configs.recommended,
|
||||
nextPlugin.configs["core-web-vitals"],
|
||||
{
|
||||
files: ["**/*.{ts,tsx,jsx}"],
|
||||
plugins: {
|
||||
"react-hooks": reactHooksPlugin,
|
||||
},
|
||||
rules: {
|
||||
"react-hooks/rules-of-hooks": "error",
|
||||
"react-hooks/exhaustive-deps": "error",
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["**/*.{js,mjs,cjs}"],
|
||||
languageOptions: {
|
||||
globals: {
|
||||
...globals.browser,
|
||||
...globals.node,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
files: ["**/*.{ts,tsx}"],
|
||||
plugins: {
|
||||
"@typescript-eslint": tsPlugin,
|
||||
import: importPlugin,
|
||||
},
|
||||
languageOptions: {
|
||||
parser: tsParser,
|
||||
ecmaVersion: "latest",
|
||||
sourceType: "module",
|
||||
parserOptions: {
|
||||
ecmaFeatures: { jsx: true },
|
||||
project: "./tsconfig.json",
|
||||
},
|
||||
},
|
||||
settings: {
|
||||
"import/resolver": {
|
||||
typescript: true,
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
...tsPlugin.configs.recommended.rules,
|
||||
...importPlugin.configs.recommended.rules,
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": [
|
||||
"error",
|
||||
{
|
||||
argsIgnorePattern: "^_",
|
||||
varsIgnorePattern: "^_",
|
||||
},
|
||||
],
|
||||
"no-undef": "off",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/ban-ts-comment": "off",
|
||||
"@next/next/no-img-element": "off",
|
||||
"no-restricted-imports": [
|
||||
"error",
|
||||
{
|
||||
paths: [
|
||||
{
|
||||
name: "next/image",
|
||||
message:
|
||||
"Use of next/image is forbidden. Use regular <img> elements instead.",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
// Server components and server actions: must use logger, not console.*
|
||||
{
|
||||
files: [
|
||||
"src/lib/server/**/*.ts",
|
||||
"src/app/**/route.ts",
|
||||
"src/middleware.ts",
|
||||
"src/lib/cookies.ts",
|
||||
],
|
||||
rules: {
|
||||
"no-console": "warn",
|
||||
},
|
||||
},
|
||||
// instrumentation.ts uses console.log during OTEL initialization (before logger is available)
|
||||
{
|
||||
files: ["src/instrumentation.ts"],
|
||||
rules: {
|
||||
"no-console": "off",
|
||||
},
|
||||
},
|
||||
// Client components: logger import is forbidden (enforced by server-only at build time)
|
||||
{
|
||||
files: ["src/components/**/*.tsx"],
|
||||
rules: {
|
||||
"no-restricted-imports": [
|
||||
"error",
|
||||
{
|
||||
paths: [
|
||||
{
|
||||
name: "next/image",
|
||||
message:
|
||||
"Use of next/image is forbidden. Use regular <img> elements instead.",
|
||||
},
|
||||
{
|
||||
name: "@/lib/logger",
|
||||
message:
|
||||
"Cannot import logger in client components. Use console.* instead. The logger uses 'server-only' and will fail at build time.",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
// Test files: allow console.*
|
||||
{
|
||||
files: [
|
||||
"**/*.test.ts",
|
||||
"**/*.test.tsx",
|
||||
"**/*.spec.ts",
|
||||
"**/*.spec.tsx",
|
||||
"**/tests/**/*",
|
||||
],
|
||||
rules: {
|
||||
"no-console": "off",
|
||||
},
|
||||
},
|
||||
prettierConfig,
|
||||
];
|
||||
@@ -1,10 +0,0 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
// Use basic ESLint config since the login app has its own detailed config
|
||||
extends: ["eslint:recommended"],
|
||||
settings: {
|
||||
next: {
|
||||
rootDir: ["apps/*/"],
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
import js from "@eslint/js";
|
||||
import tsPlugin from "@typescript-eslint/eslint-plugin";
|
||||
import tsParser from "@typescript-eslint/parser";
|
||||
import prettierConfig from "eslint-config-prettier/flat";
|
||||
import pluginCypress from "eslint-plugin-cypress";
|
||||
|
||||
export default [
|
||||
{ ignores: ["node_modules/**"] },
|
||||
js.configs.recommended,
|
||||
{
|
||||
files: ["**/*.ts"],
|
||||
plugins: {
|
||||
"@typescript-eslint": tsPlugin,
|
||||
},
|
||||
languageOptions: {
|
||||
parser: tsParser,
|
||||
ecmaVersion: "latest",
|
||||
sourceType: "module",
|
||||
},
|
||||
rules: {
|
||||
...tsPlugin.configs.recommended.rules,
|
||||
"no-unused-vars": "off",
|
||||
"no-undef": "off",
|
||||
"@typescript-eslint/no-unused-vars": [
|
||||
"error",
|
||||
{ argsIgnorePattern: "^_" },
|
||||
],
|
||||
},
|
||||
},
|
||||
pluginCypress.configs.recommended,
|
||||
prettierConfig,
|
||||
];
|
||||
+12
-8
@@ -8,11 +8,11 @@
|
||||
"build-vercel": "next build",
|
||||
"dev": "HOSTNAME=127.0.0.1 ./scripts/entrypoint.sh next dev",
|
||||
"prod": "cd ./.next/standalone && HOSTNAME=127.0.0.1 ./entrypoint.sh node apps/login/server.js",
|
||||
"lint-check-next": "next lint",
|
||||
"lint-check-next": "eslint .",
|
||||
"lint-check-prettier": "prettier --check .",
|
||||
"lint-fix": "prettier --write .",
|
||||
"test-unit": "vitest --run",
|
||||
"test-dockerized": "vitest --run --config vitest.config.dockerized.mts",
|
||||
"test-dockerized": "vitest --run --config vitest.config.dockerized.ts",
|
||||
"lint-staged": "lint-staged",
|
||||
"clean": "rm -rf node_modules .next cypress"
|
||||
},
|
||||
@@ -55,8 +55,9 @@
|
||||
"winston": "^3.17.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/eslint-parser": "^7.28.6",
|
||||
"@eslint/js": "^10.0.0",
|
||||
"@faker-js/faker": "^9.9.0",
|
||||
"@next/eslint-plugin-next": "16.1.6",
|
||||
"@opentelemetry/sdk-trace-base": "^2.5.0",
|
||||
"@opentelemetry/sdk-trace-node": "^2.5.0",
|
||||
"@otplib/core": "^12.0.1",
|
||||
@@ -72,8 +73,8 @@
|
||||
"@types/react-dom": "19.2.3",
|
||||
"@types/tinycolor2": "^1.4.6",
|
||||
"@types/uuid": "^10.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.54.0",
|
||||
"@typescript-eslint/parser": "^8.54.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.57.0",
|
||||
"@typescript-eslint/parser": "^8.57.0",
|
||||
"@vercel/git-hooks": "1.0.0",
|
||||
"@vitejs/plugin-react": "^4.7.0",
|
||||
"@zitadel/client": "workspace:*",
|
||||
@@ -84,11 +85,14 @@
|
||||
"dotenv-cli": "^8.0.0",
|
||||
"env-cmd": "^10.1.0",
|
||||
"esbuild": "^0.27.3",
|
||||
"eslint": "^8.57.1",
|
||||
"eslint-config-next": "15.5.9",
|
||||
"eslint-config-prettier": "^9.1.2",
|
||||
"eslint": "^10.0.0",
|
||||
"eslint-config-prettier": "^10.1.8",
|
||||
"eslint-import-resolver-typescript": "^4.4.4",
|
||||
"eslint-plugin-cypress": "^4.2.0",
|
||||
"eslint-plugin-import": "^2.32.0",
|
||||
"eslint-plugin-react-hooks": "^7.0.1",
|
||||
"gaxios": "^7.1.3",
|
||||
"globals": "^17.0.0",
|
||||
"grpc-tools": "^1.13.1",
|
||||
"jsdom": "^26.1.0",
|
||||
"lint-staged": "15.5.1",
|
||||
|
||||
@@ -129,7 +129,7 @@
|
||||
"options": {
|
||||
"cwd": "{projectRoot}",
|
||||
"commands": [
|
||||
"pnpm vitest --run --config vitest.config.dockerized.mts"
|
||||
"pnpm vitest --run --config vitest.config.dockerized.ts"
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -149,7 +149,7 @@
|
||||
"options": {
|
||||
"cwd": "{projectRoot}",
|
||||
"commands": [
|
||||
"pnpm vitest --run --config vitest.config.dockerized.mts dockerized/ssl"
|
||||
"pnpm vitest --run --config vitest.config.dockerized.ts dockerized/ssl"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
@@ -13,30 +13,21 @@ interface AvatarProps {
|
||||
}
|
||||
|
||||
export function getInitials(name: string, loginName: string) {
|
||||
let credentials = "";
|
||||
if (name) {
|
||||
const split = name.split(" ");
|
||||
if (split) {
|
||||
const initials = split[0].charAt(0) + (split[1] ? split[1].charAt(0) : "");
|
||||
credentials = initials;
|
||||
} else {
|
||||
credentials = name.charAt(0);
|
||||
}
|
||||
} else {
|
||||
const username = loginName.split("@")[0];
|
||||
let separator = "_";
|
||||
if (username.includes("-")) {
|
||||
separator = "-";
|
||||
}
|
||||
if (username.includes(".")) {
|
||||
separator = ".";
|
||||
}
|
||||
const split = username.split(separator);
|
||||
const initials = split[0].charAt(0) + (split[1] ? split[1].charAt(0) : "");
|
||||
credentials = initials;
|
||||
return split[0].charAt(0) + (split[1] ? split[1].charAt(0) : "");
|
||||
}
|
||||
|
||||
return credentials;
|
||||
const username = loginName.split("@")[0];
|
||||
let separator = "_";
|
||||
if (username.includes("-")) {
|
||||
separator = "-";
|
||||
}
|
||||
if (username.includes(".")) {
|
||||
separator = ".";
|
||||
}
|
||||
const split = username.split(separator);
|
||||
return split[0].charAt(0) + (split[1] ? split[1].charAt(0) : "");
|
||||
}
|
||||
|
||||
// Helper function to get avatar roundness from theme
|
||||
|
||||
@@ -65,7 +65,6 @@ function getDefaultButtonAppearance(): string {
|
||||
return appearance?.button || "border border-button-light-border dark:border-button-dark-border"; // Fallback to flat design
|
||||
}
|
||||
|
||||
// eslint-disable-next-line react/display-name
|
||||
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
|
||||
(
|
||||
{
|
||||
|
||||
@@ -35,7 +35,6 @@ function getDefaultCardStyling(): string {
|
||||
return appearance?.card || "shadow-sm border-0"; // Fallback to material design
|
||||
}
|
||||
|
||||
// eslint-disable-next-line react/display-name
|
||||
export const Card = forwardRef<HTMLDivElement, CardProps>(
|
||||
(
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(function Che
|
||||
checked={enabled}
|
||||
onChange={(event) => {
|
||||
setEnabled(event.target?.checked);
|
||||
onChangeVal && onChangeVal(event.target?.checked);
|
||||
if (onChangeVal) onChangeVal(event.target?.checked);
|
||||
}}
|
||||
disabled={disabled}
|
||||
type="checkbox"
|
||||
|
||||
@@ -17,7 +17,7 @@ export function CopyToClipboard({ value }: Props) {
|
||||
const to = setTimeout(setCopied, 1000, false);
|
||||
return () => clearTimeout(to);
|
||||
}
|
||||
}, [copied]);
|
||||
}, [copied, value]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-row items-center px-2">
|
||||
|
||||
@@ -91,7 +91,7 @@ export function IdpProcessHandler({
|
||||
setError(err instanceof Error ? err.message : t("processing.unexpectedError"));
|
||||
setLoading(false);
|
||||
});
|
||||
}, [provider, id, token, requestId, organization, link, sessionId, postErrorRedirectUrl, router]);
|
||||
}, [provider, id, token, requestId, organization, link, sessionId, linkFingerprint, postErrorRedirectUrl, router, t]);
|
||||
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center">
|
||||
|
||||
@@ -37,7 +37,6 @@ function getDefaultInputRoundness(): string {
|
||||
return getComponentRoundness("input");
|
||||
}
|
||||
|
||||
// eslint-disable-next-line react/display-name
|
||||
export const TextInput = forwardRef<HTMLInputElement, TextInputProps>(
|
||||
(
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ import { Button, ButtonVariants } from "./button";
|
||||
import { Spinner } from "./spinner";
|
||||
import { Translated } from "./translated";
|
||||
|
||||
type Inputs = {};
|
||||
type Inputs = Record<string, never>;
|
||||
|
||||
type Props = {
|
||||
sessionId?: string;
|
||||
@@ -44,6 +44,35 @@ export function RegisterPasskey({
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const continueAndLogin = useCallback(
|
||||
(loginName?: string) => {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
if (organization) {
|
||||
params.set("organization", organization);
|
||||
}
|
||||
|
||||
if (requestId) {
|
||||
params.set("requestId", requestId);
|
||||
}
|
||||
|
||||
if (sessionId) {
|
||||
params.set("sessionId", sessionId);
|
||||
}
|
||||
|
||||
if (userId) {
|
||||
params.set("userId", userId);
|
||||
}
|
||||
|
||||
if (loginName ?? initialLoginName) {
|
||||
params.set("loginName", loginName ?? initialLoginName ?? "");
|
||||
}
|
||||
|
||||
router.push("/passkey?" + params);
|
||||
},
|
||||
[organization, requestId, sessionId, userId, initialLoginName, router],
|
||||
);
|
||||
|
||||
async function submitVerify(
|
||||
passkeyId: string,
|
||||
passkeyName: string,
|
||||
@@ -166,7 +195,7 @@ export function RegisterPasskey({
|
||||
}
|
||||
|
||||
continueAndLogin(verificationResponse.loginName);
|
||||
}, [sessionId, userId, code]);
|
||||
}, [sessionId, userId, code, codeId, continueAndLogin]);
|
||||
|
||||
// Auto-submit when code is provided (similar to VerifyForm)
|
||||
useEffect(() => {
|
||||
@@ -175,32 +204,6 @@ export function RegisterPasskey({
|
||||
}
|
||||
}, [code, submitRegisterAndContinue]);
|
||||
|
||||
function continueAndLogin(loginName?: string) {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
if (organization) {
|
||||
params.set("organization", organization);
|
||||
}
|
||||
|
||||
if (requestId) {
|
||||
params.set("requestId", requestId);
|
||||
}
|
||||
|
||||
if (sessionId) {
|
||||
params.set("sessionId", sessionId);
|
||||
}
|
||||
|
||||
if (userId) {
|
||||
params.set("userId", userId);
|
||||
}
|
||||
|
||||
if (loginName ?? initialLoginName) {
|
||||
params.set("loginName", loginName ?? initialLoginName ?? "");
|
||||
}
|
||||
|
||||
router.push("/passkey?" + params);
|
||||
}
|
||||
|
||||
return (
|
||||
<form className="w-full">
|
||||
{error && (
|
||||
|
||||
@@ -4,7 +4,7 @@ import { clearSession } from "@/lib/server/session";
|
||||
import { timestampDate } from "@zitadel/client";
|
||||
import { Session } from "@zitadel/proto/zitadel/session/v2/session_pb";
|
||||
import { redirect, useRouter } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { Alert, AlertType } from "./alert";
|
||||
import { SessionClearItem } from "./session-clear-item";
|
||||
import { Translated } from "./translated";
|
||||
@@ -20,7 +20,7 @@ export function SessionsClearList({ sessions, logoutHint, postLogoutRedirectUri,
|
||||
const [list, setList] = useState<Session[]>(sessions);
|
||||
const router = useRouter();
|
||||
|
||||
async function clearHintedSession() {
|
||||
const clearHintedSession = useCallback(async () => {
|
||||
console.log("Clearing session for login hint:", logoutHint);
|
||||
// If a login hint is provided, we logout that specific session
|
||||
const sessionIdToBeCleared = sessions.find((session) => {
|
||||
@@ -53,13 +53,13 @@ export function SessionsClearList({ sessions, logoutHint, postLogoutRedirectUri,
|
||||
} else {
|
||||
console.warn(`No session found for login hint: ${logoutHint}`);
|
||||
}
|
||||
}
|
||||
}, [logoutHint, sessions, postLogoutRedirectUri, organization, router]);
|
||||
|
||||
useEffect(() => {
|
||||
if (logoutHint) {
|
||||
clearHintedSession();
|
||||
}
|
||||
}, []);
|
||||
}, [logoutHint, clearHintedSession]);
|
||||
|
||||
return sessions ? (
|
||||
<div className="flex flex-col space-y-2">
|
||||
|
||||
@@ -5,7 +5,7 @@ import { sendLoginname } from "@/lib/server/loginname";
|
||||
import { LoginSettings } from "@zitadel/proto/zitadel/settings/v2/login_settings_pb";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { Alert } from "./alert";
|
||||
import { AutoSubmitForm } from "./auto-submit-form";
|
||||
@@ -55,34 +55,37 @@ export function UsernameForm({
|
||||
const [error, setError] = useState<string>("");
|
||||
const [samlData, setSamlData] = useState<{ url: string; fields: Record<string, string> } | null>(null);
|
||||
|
||||
async function submitLoginName(values: Inputs, organization?: string) {
|
||||
setLoading(true);
|
||||
const submitLoginName = useCallback(
|
||||
async (values: Inputs, organization?: string) => {
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
const res = await sendLoginname({
|
||||
loginName: values.loginName,
|
||||
organization,
|
||||
defaultOrganization,
|
||||
requestId,
|
||||
suffix,
|
||||
ignoreUnknownUsernames: loginSettings?.ignoreUnknownUsernames,
|
||||
});
|
||||
try {
|
||||
const res = await sendLoginname({
|
||||
loginName: values.loginName,
|
||||
organization,
|
||||
defaultOrganization,
|
||||
requestId,
|
||||
suffix,
|
||||
ignoreUnknownUsernames: loginSettings?.ignoreUnknownUsernames,
|
||||
});
|
||||
|
||||
handleServerActionResponse(res, router, setSamlData, setError);
|
||||
return res;
|
||||
} catch {
|
||||
setError(t("errors.internalError"));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
handleServerActionResponse(res, router, setSamlData, setError);
|
||||
return res;
|
||||
} catch {
|
||||
setError(t("errors.internalError"));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[defaultOrganization, requestId, suffix, loginSettings, router, t],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (submit && loginName) {
|
||||
// When we navigate to this page, we always want to be redirected if submit is true and the parameters are valid.
|
||||
submitLoginName({ loginName }, organization);
|
||||
}
|
||||
}, []);
|
||||
}, [submit, loginName, organization, submitLoginName]);
|
||||
|
||||
let inputLabel = t("labels.loginname");
|
||||
if (loginSettings?.disableLoginWithEmail && loginSettings?.disableLoginWithPhone) {
|
||||
|
||||
@@ -101,7 +101,7 @@ export function VerifyForm({ userId, loginName, organization, requestId, code, i
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[isInvite, userId],
|
||||
[isInvite, userId, loginName, organization, requestId, router, t],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -341,58 +341,39 @@ export function hashCode(str: string, seed = 0): number {
|
||||
|
||||
export function getMembershipColor(role: string): ColorShade {
|
||||
const hash = hashCode(role);
|
||||
let color = COLORS[hash % COLORS.length];
|
||||
|
||||
switch (role) {
|
||||
case "IAM_OWNER":
|
||||
color = COLORS[0];
|
||||
break;
|
||||
return COLORS[0];
|
||||
case "IAM_OWNER_VIEWER":
|
||||
color = COLORS[14];
|
||||
break;
|
||||
return COLORS[14];
|
||||
case "IAM_ORG_MANAGER":
|
||||
color = COLORS[11];
|
||||
break;
|
||||
return COLORS[11];
|
||||
case "IAM_USER_MANAGER":
|
||||
color = COLORS[8];
|
||||
break;
|
||||
return COLORS[8];
|
||||
|
||||
case "ORG_OWNER":
|
||||
color = COLORS[16];
|
||||
break;
|
||||
return COLORS[16];
|
||||
case "ORG_USER_MANAGER":
|
||||
color = COLORS[8];
|
||||
break;
|
||||
return COLORS[8];
|
||||
case "ORG_OWNER_VIEWER":
|
||||
color = COLORS[14];
|
||||
break;
|
||||
return COLORS[14];
|
||||
case "ORG_USER_PERMISSION_EDITOR":
|
||||
color = COLORS[7];
|
||||
break;
|
||||
return COLORS[7];
|
||||
case "ORG_PROJECT_PERMISSION_EDITOR":
|
||||
color = COLORS[11];
|
||||
break;
|
||||
return COLORS[11];
|
||||
case "ORG_PROJECT_CREATOR":
|
||||
color = COLORS[12];
|
||||
break;
|
||||
return COLORS[12];
|
||||
|
||||
case "PROJECT_OWNER":
|
||||
color = COLORS[9];
|
||||
break;
|
||||
return COLORS[9];
|
||||
case "PROJECT_OWNER_VIEWER":
|
||||
color = COLORS[10];
|
||||
break;
|
||||
return COLORS[10];
|
||||
case "PROJECT_OWNER_GLOBAL":
|
||||
color = COLORS[11];
|
||||
break;
|
||||
return COLORS[11];
|
||||
case "PROJECT_OWNER_VIEWER_GLOBAL":
|
||||
color = COLORS[12];
|
||||
break;
|
||||
return COLORS[12];
|
||||
|
||||
default:
|
||||
color = COLORS[hash % COLORS.length];
|
||||
break;
|
||||
return COLORS[hash % COLORS.length];
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ export default getRequestConfig(async () => {
|
||||
|
||||
const i18nOrganization = _headers.get("x-zitadel-i18n-organization") || ""; // You may need to set this header in middleware
|
||||
|
||||
let translations: JsonObject | {} = {};
|
||||
let translations: JsonObject | Record<string, never> = {};
|
||||
try {
|
||||
const i18nJSON = await getHostedLoginTranslation({
|
||||
serviceConfig,
|
||||
|
||||
@@ -46,6 +46,8 @@ export async function loginServiceKeyToken() {
|
||||
key: key,
|
||||
});
|
||||
} catch (err) {
|
||||
throw new Error(`Failed to read login service key file "${keyFile}": ${err instanceof Error ? err.message : err}`);
|
||||
throw new Error(`Failed to read login service key file "${keyFile}": ${err instanceof Error ? err.message : err}`, {
|
||||
cause: err,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,24 +374,26 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
||||
};
|
||||
}
|
||||
|
||||
const paramsPassword = new URLSearchParams({
|
||||
loginName: command.ignoreUnknownUsernames
|
||||
? command.loginName
|
||||
: (session?.factors?.user?.loginName ?? user.preferredLoginName),
|
||||
});
|
||||
{
|
||||
const paramsPassword = new URLSearchParams({
|
||||
loginName: command.ignoreUnknownUsernames
|
||||
? command.loginName
|
||||
: (session?.factors?.user?.loginName ?? user.preferredLoginName),
|
||||
});
|
||||
|
||||
if (organization) {
|
||||
paramsPassword.append("organization", organization);
|
||||
if (organization) {
|
||||
paramsPassword.append("organization", organization);
|
||||
}
|
||||
|
||||
if (command.requestId) {
|
||||
paramsPassword.append("requestId", command.requestId);
|
||||
}
|
||||
|
||||
return {
|
||||
redirect: "/password?" + paramsPassword,
|
||||
};
|
||||
}
|
||||
|
||||
if (command.requestId) {
|
||||
paramsPassword.append("requestId", command.requestId);
|
||||
}
|
||||
|
||||
return {
|
||||
redirect: "/password?" + paramsPassword,
|
||||
};
|
||||
|
||||
case AuthenticationMethodType.PASSKEY: // AuthenticationMethodType.AUTHENTICATION_METHOD_TYPE_PASSKEY
|
||||
if (userLoginSettings?.passkeysType === PasskeysType.NOT_ALLOWED || !userLoginSettings?.allowLocalAuthentication) {
|
||||
if (command.ignoreUnknownUsernames) {
|
||||
@@ -402,22 +404,24 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
||||
};
|
||||
}
|
||||
|
||||
const paramsPasskey = new URLSearchParams({
|
||||
loginName: command.ignoreUnknownUsernames
|
||||
? command.loginName
|
||||
: (session?.factors?.user?.loginName ?? user.preferredLoginName),
|
||||
});
|
||||
if (command.requestId) {
|
||||
paramsPasskey.append("requestId", command.requestId);
|
||||
{
|
||||
const paramsPasskey = new URLSearchParams({
|
||||
loginName: command.ignoreUnknownUsernames
|
||||
? command.loginName
|
||||
: (session?.factors?.user?.loginName ?? user.preferredLoginName),
|
||||
});
|
||||
if (command.requestId) {
|
||||
paramsPasskey.append("requestId", command.requestId);
|
||||
}
|
||||
|
||||
if (organization) {
|
||||
paramsPasskey.append("organization", organization);
|
||||
}
|
||||
|
||||
return { redirect: "/passkey?" + paramsPasskey };
|
||||
}
|
||||
|
||||
if (organization) {
|
||||
paramsPasskey.append("organization", organization);
|
||||
}
|
||||
|
||||
return { redirect: "/passkey?" + paramsPasskey };
|
||||
|
||||
case AuthenticationMethodType.IDP:
|
||||
case AuthenticationMethodType.IDP: {
|
||||
const resp = await redirectUserToIDP(userId, organization);
|
||||
|
||||
if (resp?.error) {
|
||||
@@ -425,6 +429,7 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
||||
}
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// prefer passkey in favor of other methods
|
||||
|
||||
@@ -317,7 +317,6 @@ describe("sendPassword", () => {
|
||||
const { completeFlowOrGetUrl } = await import("../client");
|
||||
vi.mocked(completeFlowOrGetUrl).mockResolvedValue({ redirect: "https://example.com" });
|
||||
|
||||
// eslint-disable-next-line
|
||||
const verifyHelper = await import("../verify-helper");
|
||||
vi.mocked(verifyHelper.checkPasswordChangeRequired).mockReturnValue(undefined);
|
||||
vi.mocked(verifyHelper.checkEmailVerification).mockReturnValue(undefined);
|
||||
|
||||
@@ -293,7 +293,7 @@ export async function sendPassword(
|
||||
return {
|
||||
error: t(messageKey, {
|
||||
failedAttempts: error.failedAttempts,
|
||||
maxPasswordAttempts: hasLimit ? (lockoutSettings?.maxPasswordAttempts).toString() : "?",
|
||||
maxPasswordAttempts: hasLimit ? String(lockoutSettings?.maxPasswordAttempts ?? 0) : "?",
|
||||
lockoutMessage: locked ? t("errors.accountLockedContactAdmin") : "",
|
||||
}),
|
||||
};
|
||||
@@ -565,7 +565,7 @@ export async function checkSessionAndSetPassword({
|
||||
return {
|
||||
error: t(messageKey, {
|
||||
failedAttempts: error.failedAttempts,
|
||||
maxPasswordAttempts: hasLimit ? (lockoutSettings?.maxPasswordAttempts).toString() : "?",
|
||||
maxPasswordAttempts: hasLimit ? String(lockoutSettings?.maxPasswordAttempts ?? 0) : "?",
|
||||
lockoutMessage: locked ? t("errors.accountLockedContactAdmin") : "",
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -164,6 +164,7 @@ export async function checkMFAFactors(
|
||||
|
||||
// TODO: provide a way to setup passkeys on mfa page?
|
||||
return { redirect: `/mfa/set?` + params };
|
||||
/* eslint-disable no-dupe-else-if -- TODO: this branch is unreachable, conditions overlap with the previous branch */
|
||||
} else if (
|
||||
loginSettings?.mfaInitSkipLifetime &&
|
||||
(loginSettings.mfaInitSkipLifetime.nanos > 0 || loginSettings.mfaInitSkipLifetime.seconds > 0) &&
|
||||
@@ -171,6 +172,7 @@ export async function checkMFAFactors(
|
||||
session?.factors?.user?.id &&
|
||||
shouldEnforceMFA(session, loginSettings)
|
||||
) {
|
||||
/* eslint-enable no-dupe-else-if */
|
||||
const userResponse = await getUserByID({ serviceConfig, userId: session.factors?.user?.id });
|
||||
|
||||
const humanUser = userResponse?.user?.type.case === "human" ? userResponse?.user.type.value : undefined;
|
||||
|
||||
@@ -1237,20 +1237,18 @@ export interface ServiceConfig {
|
||||
/**
|
||||
* Base type that all function parameters must extend to ensure serviceConfig is always required
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
||||
export type WithServiceConfig<T = {}> = T & {
|
||||
serviceConfig: ServiceConfig;
|
||||
};
|
||||
|
||||
export function createServerTransport(token: string, serviceConfig: ServiceConfig) {
|
||||
// Build interceptors list - OTEL interceptor is always included for trace propagation
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const interceptors: any[] = [otelGrpcInterceptor];
|
||||
|
||||
// Add custom headers interceptor if needed
|
||||
if (process.env.CUSTOM_REQUEST_HEADERS || serviceConfig.instanceHost || serviceConfig.publicHost) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
interceptors.push((next: any) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return (req: any) => {
|
||||
// Apply headers from serviceConfig
|
||||
if (serviceConfig.instanceHost) {
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
"node_modules",
|
||||
"integration",
|
||||
"acceptance",
|
||||
"dockerized"
|
||||
"dockerized",
|
||||
"vitest.config*.ts"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user