feat(http-auth): resolve profiles by UUID and allow multi-auth triggers
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,422 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { LuEye, LuEyeOff } from "react-icons/lu";
|
||||
import { errorMessage } from "../api/client.js";
|
||||
import {
|
||||
fetchHttpAuthLiterals,
|
||||
useHttpPages,
|
||||
useUpsertHttpAuth,
|
||||
} from "../api/hooks.js";
|
||||
|
||||
function emptyCred(source = "literal") {
|
||||
return { source, value: "", kv: "", namespace: "", secret: "" };
|
||||
}
|
||||
|
||||
function credFromPublic(field, literalValue) {
|
||||
if (!field || field.source === "missing") return emptyCred("literal");
|
||||
if (field.source === "kv") {
|
||||
return {
|
||||
source: "kv",
|
||||
value: "",
|
||||
kv: field.kv ?? "",
|
||||
namespace: field.namespace ?? "",
|
||||
secret: "",
|
||||
};
|
||||
}
|
||||
if (field.source === "secret") {
|
||||
return {
|
||||
source: "secret",
|
||||
value: "",
|
||||
kv: "",
|
||||
namespace: "",
|
||||
secret: field.secret ?? "",
|
||||
};
|
||||
}
|
||||
if (typeof literalValue === "string") {
|
||||
return {
|
||||
source: "literal",
|
||||
value: literalValue,
|
||||
kv: "",
|
||||
namespace: "",
|
||||
secret: "",
|
||||
keep: true,
|
||||
};
|
||||
}
|
||||
return {
|
||||
source: "literal",
|
||||
value: "",
|
||||
kv: "",
|
||||
namespace: "",
|
||||
secret: "",
|
||||
keep: field.set === true,
|
||||
};
|
||||
}
|
||||
|
||||
function toApiField(cred, { required = true } = {}) {
|
||||
if (cred.source === "kv") {
|
||||
const out = { kv: cred.kv };
|
||||
if (cred.namespace) out.namespace = cred.namespace;
|
||||
return out;
|
||||
}
|
||||
if (cred.source === "secret") {
|
||||
return { secret: cred.secret };
|
||||
}
|
||||
if (cred.value) return cred.value;
|
||||
if (cred.keep) return { keep: true };
|
||||
if (!required) return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
function emptyForm() {
|
||||
return {
|
||||
id: null,
|
||||
name: "",
|
||||
type: "bearer",
|
||||
token: emptyCred(),
|
||||
user: emptyCred(),
|
||||
password: emptyCred(),
|
||||
header: "",
|
||||
value: emptyCred(),
|
||||
unauthorized_status: "",
|
||||
unauthorized_response: "",
|
||||
};
|
||||
}
|
||||
|
||||
function formFromAuth(auth, literals = {}) {
|
||||
const cfg = auth.config ?? {};
|
||||
return {
|
||||
id: auth.id,
|
||||
name: auth.name,
|
||||
type: auth.type,
|
||||
token: credFromPublic(cfg.token, literals.token),
|
||||
user: credFromPublic(cfg.user, literals.user),
|
||||
password: credFromPublic(cfg.password, literals.password),
|
||||
header: cfg.header ?? "",
|
||||
value: credFromPublic(cfg.value, literals.value),
|
||||
unauthorized_status: auth.unauthorized_status ?? "",
|
||||
unauthorized_response: auth.unauthorized_response ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
function Field({ label, children, hint }) {
|
||||
return (
|
||||
<div className="form-control w-full">
|
||||
<div className="label py-1">
|
||||
<span className="label-text text-sm font-medium">{label}</span>
|
||||
</div>
|
||||
{children}
|
||||
{hint ? (
|
||||
<div className="label py-1">
|
||||
<span className="label-text-alt opacity-60">{hint}</span>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function CredentialFields({ label, cred, onChange, allowEmpty, masked }) {
|
||||
const [show, setShow] = useState(false);
|
||||
|
||||
return (
|
||||
<div className="space-y-3 rounded-box border border-base-300 p-3">
|
||||
<p className="text-sm font-medium">{label}</p>
|
||||
<Field label="Source">
|
||||
<select
|
||||
className="select select-bordered w-full"
|
||||
value={cred.source}
|
||||
onChange={(e) => onChange({ ...cred, source: e.target.value, keep: false })}
|
||||
>
|
||||
<option value="literal">Plain text</option>
|
||||
<option value="kv">From KV</option>
|
||||
<option value="secret">From secret</option>
|
||||
</select>
|
||||
</Field>
|
||||
{cred.source === "literal" ? (
|
||||
<Field
|
||||
label="Value"
|
||||
hint={
|
||||
cred.keep && !cred.value
|
||||
? "A value is already set. Enter a new one to replace it."
|
||||
: null
|
||||
}
|
||||
>
|
||||
<div className="flex w-full gap-1">
|
||||
<input
|
||||
type={masked && !show ? "password" : "text"}
|
||||
className="input input-bordered w-full font-mono"
|
||||
value={cred.value}
|
||||
onChange={(e) => onChange({ ...cred, value: e.target.value, keep: false })}
|
||||
placeholder={
|
||||
cred.keep && !cred.value ? "(unchanged — leave blank to keep)" : ""
|
||||
}
|
||||
required={!allowEmpty && !cred.keep && !cred.value}
|
||||
autoComplete="off"
|
||||
/>
|
||||
{masked ? (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost btn-square shrink-0"
|
||||
title={show ? "Hide" : "Reveal"}
|
||||
aria-label={show ? "Hide value" : "Reveal value"}
|
||||
onClick={() => setShow((v) => !v)}
|
||||
>
|
||||
{show ? <LuEyeOff className="size-4" /> : <LuEye className="size-4" />}
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
</Field>
|
||||
) : null}
|
||||
{cred.source === "kv" ? (
|
||||
<>
|
||||
<Field label="Namespace (optional)">
|
||||
<input
|
||||
className="input input-bordered w-full font-mono"
|
||||
placeholder="namespace"
|
||||
value={cred.namespace}
|
||||
onChange={(e) => onChange({ ...cred, namespace: e.target.value })}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Key">
|
||||
<input
|
||||
className="input input-bordered w-full font-mono"
|
||||
placeholder="key"
|
||||
value={cred.kv}
|
||||
onChange={(e) => onChange({ ...cred, kv: e.target.value })}
|
||||
required
|
||||
/>
|
||||
</Field>
|
||||
</>
|
||||
) : null}
|
||||
{cred.source === "secret" ? (
|
||||
<Field
|
||||
label="Secret name"
|
||||
hint="Encrypted secret — value is never shown here. Manage it on the Secrets page."
|
||||
>
|
||||
<input
|
||||
className="input input-bordered w-full font-mono"
|
||||
placeholder="secret name"
|
||||
value={cred.secret}
|
||||
onChange={(e) => onChange({ ...cred, secret: e.target.value })}
|
||||
required
|
||||
pattern="[A-Za-z0-9._-]+"
|
||||
/>
|
||||
</Field>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add / edit an HTTP trigger auth profile.
|
||||
* Reusable: mount when open; pass `auth` for edit (literals loaded inside).
|
||||
*
|
||||
* @param {"add" | "edit"} mode
|
||||
* @param {object} [auth] Public auth row when mode is "edit"
|
||||
* @param {() => void} onClose
|
||||
* @param {(saved: unknown) => void} [onSaved]
|
||||
*/
|
||||
export function AuthEditorModal({ mode, auth, onClose, onSaved }) {
|
||||
const { data: pages = [] } = useHttpPages();
|
||||
const upsert = useUpsertHttpAuth();
|
||||
const [form, setForm] = useState(emptyForm);
|
||||
const [loading, setLoading] = useState(mode === "edit");
|
||||
|
||||
useEffect(() => {
|
||||
if (mode !== "edit" || !auth?.id) {
|
||||
setForm(emptyForm());
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
let cancelled = false;
|
||||
setLoading(true);
|
||||
(async () => {
|
||||
/** @type {Record<string, string>} */
|
||||
let literals = {};
|
||||
try {
|
||||
const data = await fetchHttpAuthLiterals(auth.id);
|
||||
literals = data.literals ?? {};
|
||||
} catch {
|
||||
// Form still works with keep markers
|
||||
}
|
||||
if (cancelled) return;
|
||||
setForm(formFromAuth(auth, literals));
|
||||
setLoading(false);
|
||||
})();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [mode, auth]);
|
||||
|
||||
function onSubmit(e) {
|
||||
e.preventDefault();
|
||||
/** @type {Record<string, unknown>} */
|
||||
let config = {};
|
||||
if (form.type === "bearer") {
|
||||
const token = toApiField(form.token);
|
||||
if (token == null) return;
|
||||
config = { token };
|
||||
} else if (form.type === "basic") {
|
||||
const user = toApiField(form.user);
|
||||
if (user == null) return;
|
||||
const password = toApiField(form.password, { required: false });
|
||||
config = { user, password: password ?? "" };
|
||||
} else {
|
||||
const value = toApiField(form.value);
|
||||
if (value == null) return;
|
||||
config = { header: form.header, value };
|
||||
}
|
||||
|
||||
upsert.mutate(
|
||||
{
|
||||
id: form.id,
|
||||
name: form.name,
|
||||
type: form.type,
|
||||
config,
|
||||
unauthorized_status:
|
||||
form.unauthorized_status === "" ? null : Number(form.unauthorized_status),
|
||||
unauthorized_response: form.unauthorized_response || null,
|
||||
},
|
||||
{
|
||||
onSuccess: (data) => {
|
||||
onSaved?.(data?.auth ?? data);
|
||||
onClose();
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
const title = mode === "add" ? "New auth profile" : `Edit ${form.name || auth?.name || ""}`;
|
||||
|
||||
return (
|
||||
<dialog className="modal modal-open">
|
||||
<div className="modal-box max-w-xl">
|
||||
<h3 className="font-bold">{title}</h3>
|
||||
{loading ? (
|
||||
<div className="flex justify-center py-10">
|
||||
<span className="loading loading-spinner" />
|
||||
</div>
|
||||
) : (
|
||||
<form className="mt-3 space-y-4" onSubmit={onSubmit}>
|
||||
<Field label="Name">
|
||||
<input
|
||||
className="input input-bordered w-full font-mono"
|
||||
value={form.name}
|
||||
onChange={(e) => setForm({ ...form, name: e.target.value })}
|
||||
required
|
||||
pattern="[A-Za-z0-9._-]+"
|
||||
autoComplete="off"
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="Type">
|
||||
<select
|
||||
className="select select-bordered w-full"
|
||||
value={form.type}
|
||||
onChange={(e) => setForm({ ...form, type: e.target.value })}
|
||||
>
|
||||
<option value="bearer">bearer</option>
|
||||
<option value="basic">basic</option>
|
||||
<option value="header">header</option>
|
||||
</select>
|
||||
</Field>
|
||||
|
||||
{form.type === "bearer" ? (
|
||||
<CredentialFields
|
||||
label="Token"
|
||||
cred={form.token}
|
||||
onChange={(token) => setForm({ ...form, token })}
|
||||
/>
|
||||
) : null}
|
||||
{form.type === "basic" ? (
|
||||
<>
|
||||
<CredentialFields
|
||||
label="User"
|
||||
cred={form.user}
|
||||
onChange={(user) => setForm({ ...form, user })}
|
||||
/>
|
||||
<CredentialFields
|
||||
label="Password"
|
||||
cred={form.password}
|
||||
onChange={(password) => setForm({ ...form, password })}
|
||||
allowEmpty
|
||||
masked
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
{form.type === "header" ? (
|
||||
<>
|
||||
<Field label="Header name">
|
||||
<input
|
||||
className="input input-bordered w-full font-mono"
|
||||
value={form.header}
|
||||
onChange={(e) => setForm({ ...form, header: e.target.value })}
|
||||
required
|
||||
placeholder="X-Webhook-Secret"
|
||||
/>
|
||||
</Field>
|
||||
<CredentialFields
|
||||
label="Header value"
|
||||
cred={form.value}
|
||||
onChange={(value) => setForm({ ...form, value })}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
|
||||
<Field label="Unauthorized status (optional)">
|
||||
<input
|
||||
type="number"
|
||||
className="input input-bordered w-full"
|
||||
value={form.unauthorized_status}
|
||||
onChange={(e) => setForm({ ...form, unauthorized_status: e.target.value })}
|
||||
min={100}
|
||||
max={599}
|
||||
placeholder="401"
|
||||
/>
|
||||
</Field>
|
||||
|
||||
<Field label="Unauthorized response page (optional)">
|
||||
<select
|
||||
className="select select-bordered w-full"
|
||||
value={form.unauthorized_response}
|
||||
onChange={(e) => setForm({ ...form, unauthorized_response: e.target.value })}
|
||||
>
|
||||
<option value="">(default JSON)</option>
|
||||
{pages.map((p) => (
|
||||
<option key={p.id} value={p.name}>
|
||||
{p.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Field>
|
||||
|
||||
{upsert.isError ? (
|
||||
<p className="text-error text-sm">{errorMessage(upsert.error)}</p>
|
||||
) : null}
|
||||
<div className="modal-action">
|
||||
<button type="button" className="btn btn-ghost" onClick={onClose}>
|
||||
Cancel
|
||||
</button>
|
||||
<button type="submit" className="btn btn-primary" disabled={upsert.isPending}>
|
||||
{upsert.isPending ? (
|
||||
<span className="loading loading-spinner loading-xs" />
|
||||
) : null}
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
{loading ? (
|
||||
<div className="modal-action">
|
||||
<button type="button" className="btn btn-ghost" onClick={onClose}>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
<form method="dialog" className="modal-backdrop">
|
||||
<button type="button" onClick={onClose}>
|
||||
close
|
||||
</button>
|
||||
</form>
|
||||
</dialog>
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState } from "react";
|
||||
import { LuChevronDown, LuCopy, LuGripVertical, LuTrash2 } from "react-icons/lu";
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { LuChevronDown, LuCopy, LuGripVertical, LuTrash2, LuX } from "react-icons/lu";
|
||||
import { useSortable } from "@dnd-kit/sortable";
|
||||
import { CSS } from "@dnd-kit/utilities";
|
||||
import cronstrue from "cronstrue";
|
||||
@@ -138,15 +138,27 @@ function typeLabel(type) {
|
||||
return type || "Trigger";
|
||||
}
|
||||
|
||||
function Field({ label, children, hint }) {
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-1">
|
||||
{label ? <span className="text-sm font-medium opacity-80">{label}</span> : null}
|
||||
{children}
|
||||
{hint ? <span className="text-xs opacity-60">{hint}</span> : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function HttpFields({ trigger, owner, disabled, onChange, auths, pages, alertDestinations }) {
|
||||
const path = trigger.path || "/";
|
||||
const url = namespacedPath(owner || "owner", path);
|
||||
const authIsInline = trigger.auth != null && typeof trigger.auth === "object";
|
||||
const authSelect = authIsInline
|
||||
? "__inline__"
|
||||
: typeof trigger.auth === "string" && trigger.auth
|
||||
? trigger.auth
|
||||
: "";
|
||||
const authEntries = Array.isArray(trigger.auth) ? trigger.auth : [];
|
||||
const selectedIds = authEntries.filter((e) => typeof e === "string" && e).map(String);
|
||||
const inlineEntries = authEntries.filter((e) => e && typeof e === "object");
|
||||
|
||||
function setAuthIds(nextIds) {
|
||||
const next = [...nextIds, ...inlineEntries];
|
||||
onChange({ ...trigger, auth: next.length ? next : null });
|
||||
}
|
||||
|
||||
function copyUrl() {
|
||||
if (typeof navigator?.clipboard?.writeText === "function") {
|
||||
@@ -155,11 +167,10 @@ function HttpFields({ trigger, owner, disabled, onChange, auths, pages, alertDes
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<label className="form-control">
|
||||
<span className="label py-0 text-sm">Method</span>
|
||||
<div className="space-y-3">
|
||||
<Field label="Method">
|
||||
<select
|
||||
className="select select-sm"
|
||||
className="select select-bordered select-sm w-full"
|
||||
value={trigger.method || "POST"}
|
||||
disabled={disabled}
|
||||
onChange={(e) => onChange({ ...trigger, method: e.target.value })}
|
||||
@@ -173,51 +184,48 @@ function HttpFields({ trigger, owner, disabled, onChange, auths, pages, alertDes
|
||||
<option value={trigger.method}>{trigger.method}</option>
|
||||
)}
|
||||
</select>
|
||||
</label>
|
||||
<label className="form-control">
|
||||
<span className="label py-0 text-sm">Path</span>
|
||||
</Field>
|
||||
|
||||
<Field label="Path">
|
||||
<input
|
||||
className="input input-sm font-mono"
|
||||
className="input input-bordered input-sm w-full font-mono"
|
||||
value={trigger.path ?? ""}
|
||||
disabled={disabled}
|
||||
onChange={(e) => onChange({ ...trigger, path: e.target.value })}
|
||||
placeholder="/hook"
|
||||
/>
|
||||
</label>
|
||||
<div className="flex items-center gap-2 text-xs font-mono opacity-80">
|
||||
<span className="truncate">{url}</span>
|
||||
<button type="button" className="btn btn-ghost btn-xs btn-square" title="Copy URL" onClick={copyUrl}>
|
||||
<LuCopy className="size-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
<label className="form-control">
|
||||
<span className="label py-0 text-sm">Auth</span>
|
||||
</Field>
|
||||
|
||||
<Field label="URL">
|
||||
<div className="flex w-full items-center gap-1">
|
||||
<input
|
||||
className="input input-bordered input-sm w-full font-mono opacity-80"
|
||||
value={url}
|
||||
readOnly
|
||||
tabIndex={-1}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost btn-sm btn-square shrink-0"
|
||||
title="Copy URL"
|
||||
onClick={copyUrl}
|
||||
>
|
||||
<LuCopy className="size-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
</Field>
|
||||
|
||||
<AuthPicker
|
||||
auths={auths}
|
||||
selectedIds={selectedIds}
|
||||
inlineCount={inlineEntries.length}
|
||||
disabled={disabled}
|
||||
onChange={setAuthIds}
|
||||
/>
|
||||
|
||||
<Field label="Response page">
|
||||
<select
|
||||
className="select select-sm"
|
||||
value={authSelect}
|
||||
disabled={disabled}
|
||||
onChange={(e) => {
|
||||
const v = e.target.value;
|
||||
if (v === "" || v === "__inline__") {
|
||||
onChange({ ...trigger, auth: v === "__inline__" ? trigger.auth : null });
|
||||
} else {
|
||||
onChange({ ...trigger, auth: v });
|
||||
}
|
||||
}}
|
||||
>
|
||||
<option value="">None</option>
|
||||
{auths.map((a) => (
|
||||
<option key={a.name} value={a.name}>
|
||||
{a.name}
|
||||
</option>
|
||||
))}
|
||||
{authIsInline ? <option value="__inline__">Inline (edit in YAML)</option> : null}
|
||||
</select>
|
||||
</label>
|
||||
<label className="form-control">
|
||||
<span className="label py-0 text-sm">Response page</span>
|
||||
<select
|
||||
className="select select-sm"
|
||||
className="select select-bordered select-sm w-full"
|
||||
value={trigger.response ?? ""}
|
||||
disabled={disabled}
|
||||
onChange={(e) => onChange({ ...trigger, response: e.target.value })}
|
||||
@@ -232,7 +240,8 @@ function HttpFields({ trigger, owner, disabled, onChange, auths, pages, alertDes
|
||||
<option value={trigger.response}>{trigger.response}</option>
|
||||
) : null}
|
||||
</select>
|
||||
</label>
|
||||
</Field>
|
||||
|
||||
<FailureAlertFields
|
||||
trigger={trigger}
|
||||
disabled={disabled}
|
||||
@@ -243,6 +252,165 @@ function HttpFields({ trigger, owner, disabled, onChange, auths, pages, alertDes
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Searchable dropdown: pick an auth to add; chips with X to remove.
|
||||
* YAML stores profile UUIDs; UI shows names.
|
||||
*/
|
||||
function AuthPicker({ auths, selectedIds, inlineCount, disabled, onChange }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [query, setQuery] = useState("");
|
||||
const rootRef = useRef(null);
|
||||
const inputRef = useRef(null);
|
||||
const selectedSet = useMemo(() => new Set(selectedIds), [selectedIds]);
|
||||
const byId = useMemo(() => new Map(auths.map((a) => [a.id, a])), [auths]);
|
||||
|
||||
const available = useMemo(() => {
|
||||
const q = query.trim().toLowerCase();
|
||||
return auths
|
||||
.filter((a) => !selectedSet.has(a.id))
|
||||
.filter((a) => {
|
||||
if (!q) return true;
|
||||
return (
|
||||
a.name.toLowerCase().includes(q) ||
|
||||
String(a.type).toLowerCase().includes(q) ||
|
||||
a.id.toLowerCase().includes(q)
|
||||
);
|
||||
});
|
||||
}, [auths, selectedSet, query]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
function onDoc(e) {
|
||||
if (rootRef.current && !rootRef.current.contains(e.target)) {
|
||||
setOpen(false);
|
||||
setQuery("");
|
||||
}
|
||||
}
|
||||
document.addEventListener("mousedown", onDoc);
|
||||
return () => document.removeEventListener("mousedown", onDoc);
|
||||
}, [open]);
|
||||
|
||||
function addAuth(id) {
|
||||
if (selectedSet.has(id)) return;
|
||||
onChange([...selectedIds, id]);
|
||||
setQuery("");
|
||||
setOpen(false);
|
||||
}
|
||||
|
||||
function removeAuth(id) {
|
||||
onChange(selectedIds.filter((x) => x !== id));
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-1" ref={rootRef}>
|
||||
<span className="text-sm font-medium opacity-80">Auth (any of)</span>
|
||||
|
||||
{selectedIds.length > 0 ? (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{selectedIds.map((id) => {
|
||||
const auth = byId.get(id);
|
||||
return (
|
||||
<span
|
||||
key={id}
|
||||
className="badge badge-outline gap-1 h-7 px-2 font-normal"
|
||||
title={id}
|
||||
>
|
||||
<span className="max-w-[10rem] truncate">
|
||||
{auth ? (
|
||||
<>
|
||||
{auth.name}
|
||||
<span className="opacity-60"> · {auth.type}</span>
|
||||
</>
|
||||
) : (
|
||||
<span className="opacity-60">missing</span>
|
||||
)}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost btn-xs btn-square -mr-1"
|
||||
title="Remove"
|
||||
aria-label={`Remove ${auth?.name ?? id}`}
|
||||
disabled={disabled}
|
||||
onClick={() => removeAuth(id)}
|
||||
>
|
||||
<LuX className="size-3.5" />
|
||||
</button>
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="relative w-full">
|
||||
<div className="join w-full">
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="search"
|
||||
className="input input-bordered input-sm join-item w-full min-w-0"
|
||||
placeholder={auths.length === 0 ? "No auth profiles yet" : "Add auth…"}
|
||||
value={query}
|
||||
disabled={disabled || auths.length === 0}
|
||||
onChange={(e) => {
|
||||
setQuery(e.target.value);
|
||||
setOpen(true);
|
||||
}}
|
||||
onFocus={() => setOpen(true)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Escape") {
|
||||
setOpen(false);
|
||||
setQuery("");
|
||||
inputRef.current?.blur();
|
||||
}
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
if (available[0]) addAuth(available[0].id);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-sm join-item btn-square"
|
||||
disabled={disabled || auths.length === 0}
|
||||
aria-label="Open auth list"
|
||||
onClick={() => {
|
||||
setOpen((v) => !v);
|
||||
if (!open) inputRef.current?.focus();
|
||||
}}
|
||||
>
|
||||
<LuChevronDown className={`size-4 transition-transform ${open ? "rotate-180" : ""}`} />
|
||||
</button>
|
||||
</div>
|
||||
{open && !disabled && auths.length > 0 ? (
|
||||
<ul className="menu menu-sm absolute z-50 mt-1 max-h-48 w-full overflow-y-auto rounded-box border border-base-300 bg-base-100 shadow-lg p-1">
|
||||
{available.length === 0 ? (
|
||||
<li className="disabled">
|
||||
<span className="opacity-60">
|
||||
{query.trim() ? "No matches" : "All profiles selected"}
|
||||
</span>
|
||||
</li>
|
||||
) : (
|
||||
available.map((a) => (
|
||||
<li key={a.id}>
|
||||
<button type="button" onClick={() => addAuth(a.id)}>
|
||||
<span className="font-mono text-sm">{a.name}</span>
|
||||
<span className="opacity-60 text-xs">{a.type}</span>
|
||||
</button>
|
||||
</li>
|
||||
))
|
||||
)}
|
||||
</ul>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{inlineCount > 0 ? (
|
||||
<span className="text-xs opacity-60">
|
||||
+ {inlineCount} inline auth{inlineCount === 1 ? "" : "s"} (edit in YAML)
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function CronFields({ trigger, disabled, onChange, alertDestinations }) {
|
||||
const preset = matchCronPreset(trigger.schedule);
|
||||
let human = "";
|
||||
@@ -302,12 +470,11 @@ function CronFields({ trigger, disabled, onChange, alertDestinations }) {
|
||||
|
||||
function FailureAlertFields({ trigger, disabled, onChange, alertDestinations }) {
|
||||
return (
|
||||
<div className="space-y-2 border-t border-base-300 pt-3">
|
||||
<p className="text-xs font-medium opacity-80">Failure alert</p>
|
||||
<label className="form-control">
|
||||
<span className="label py-0 text-sm">Consecutive failures</span>
|
||||
<div className="space-y-3 border-t border-base-300 pt-3">
|
||||
<p className="text-sm font-medium opacity-80">Failure alert</p>
|
||||
<Field label="Consecutive failures">
|
||||
<input
|
||||
className="input input-sm"
|
||||
className="input input-bordered input-sm w-full"
|
||||
type="number"
|
||||
min="1"
|
||||
step="1"
|
||||
@@ -318,11 +485,19 @@ function FailureAlertFields({ trigger, disabled, onChange, alertDestinations })
|
||||
}
|
||||
placeholder="e.g. 3"
|
||||
/>
|
||||
</label>
|
||||
<label className="form-control">
|
||||
<span className="label py-0 text-sm">On failure, start</span>
|
||||
</Field>
|
||||
<Field
|
||||
label="On failure, start"
|
||||
hint={
|
||||
<>
|
||||
After this many sequential failed runs for this trigger, JerapahFlow starts the
|
||||
selected workflow (it must declare a <span className="font-mono">workflow</span>{" "}
|
||||
trigger).
|
||||
</>
|
||||
}
|
||||
>
|
||||
<select
|
||||
className="select select-sm"
|
||||
className="select select-bordered select-sm w-full"
|
||||
value={trigger.onFailureWorkflow ?? ""}
|
||||
disabled={disabled}
|
||||
onChange={(e) => onChange({ ...trigger, onFailureWorkflow: e.target.value })}
|
||||
@@ -340,12 +515,7 @@ function FailureAlertFields({ trigger, disabled, onChange, alertDestinations })
|
||||
<option value={trigger.onFailureWorkflow}>{trigger.onFailureWorkflow}</option>
|
||||
) : null}
|
||||
</select>
|
||||
</label>
|
||||
<p className="text-xs opacity-60">
|
||||
After this many sequential failed runs for this trigger, JerapahFlow starts the
|
||||
selected workflow (it must declare a <span className="font-mono">workflow</span>{" "}
|
||||
trigger).
|
||||
</p>
|
||||
</Field>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ function normalizeTrigger(raw) {
|
||||
? ""
|
||||
: String(raw.onConsecutiveFailures),
|
||||
onFailureWorkflow: readOnFailureWorkflow(raw),
|
||||
auth: raw.auth ?? null,
|
||||
auth: Array.isArray(raw.auth) ? raw.auth : null,
|
||||
response: typeof raw.response === "string" ? raw.response : "",
|
||||
unauthorized: raw.unauthorized ?? null,
|
||||
extra: Object.keys(extra).length ? extra : undefined,
|
||||
@@ -345,7 +345,7 @@ function dumpTrigger(t) {
|
||||
method: t.method || "POST",
|
||||
path: t.path || "/",
|
||||
};
|
||||
if (t.auth != null && t.auth !== false && t.auth !== "") out.auth = t.auth;
|
||||
if (Array.isArray(t.auth) && t.auth.length > 0) out.auth = t.auth;
|
||||
if (t.response) out.response = t.response;
|
||||
if (t.unauthorized != null && t.unauthorized !== "") out.unauthorized = t.unauthorized;
|
||||
dumpFailureTriggerFields(t, out);
|
||||
|
||||
@@ -1,163 +1,16 @@
|
||||
import { useState } from "react";
|
||||
import { LuEye, LuEyeOff, LuPencil, LuPlus, LuTrash2, LuX } from "react-icons/lu";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useLocation, useNavigate, useParams } from "react-router-dom";
|
||||
import { LuEye, LuEyeOff, LuPencil, LuPlus, LuTrash2 } from "react-icons/lu";
|
||||
import { errorMessage } from "../api/client.js";
|
||||
import {
|
||||
fetchHttpAuthLiterals,
|
||||
useDeleteHttpAuth,
|
||||
useHttpAuths,
|
||||
useHttpPages,
|
||||
useUpsertHttpAuth,
|
||||
} from "../api/hooks.js";
|
||||
import { AuthEditorModal } from "../components/AuthEditorModal.jsx";
|
||||
import { formatTime } from "../lib/format.jsx";
|
||||
|
||||
function emptyCred(source = "literal") {
|
||||
return { source, value: "", kv: "", namespace: "", secret: "" };
|
||||
}
|
||||
|
||||
function credFromPublic(field, literalValue) {
|
||||
if (!field || field.source === "missing") return emptyCred("literal");
|
||||
if (field.source === "kv") {
|
||||
return {
|
||||
source: "kv",
|
||||
value: "",
|
||||
kv: field.kv ?? "",
|
||||
namespace: field.namespace ?? "",
|
||||
secret: "",
|
||||
};
|
||||
}
|
||||
if (field.source === "secret") {
|
||||
return {
|
||||
source: "secret",
|
||||
value: "",
|
||||
kv: "",
|
||||
namespace: "",
|
||||
secret: field.secret ?? "",
|
||||
};
|
||||
}
|
||||
// literal — prefer revealed value when available
|
||||
if (typeof literalValue === "string") {
|
||||
return {
|
||||
source: "literal",
|
||||
value: literalValue,
|
||||
kv: "",
|
||||
namespace: "",
|
||||
secret: "",
|
||||
keep: true,
|
||||
};
|
||||
}
|
||||
return {
|
||||
source: "literal",
|
||||
value: "",
|
||||
kv: "",
|
||||
namespace: "",
|
||||
secret: "",
|
||||
keep: field.set === true,
|
||||
};
|
||||
}
|
||||
|
||||
function toApiField(cred, { required = true } = {}) {
|
||||
if (cred.source === "kv") {
|
||||
const out = { kv: cred.kv };
|
||||
if (cred.namespace) out.namespace = cred.namespace;
|
||||
return out;
|
||||
}
|
||||
if (cred.source === "secret") {
|
||||
return { secret: cred.secret };
|
||||
}
|
||||
if (cred.value) return cred.value;
|
||||
if (cred.keep) return { keep: true };
|
||||
if (!required) return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
function CredentialFields({ label, cred, onChange, allowEmpty, masked }) {
|
||||
const [show, setShow] = useState(false);
|
||||
|
||||
return (
|
||||
<div className="space-y-1 border-base-300 border rounded-box p-3">
|
||||
<label className="label py-0">{label}</label>
|
||||
<select
|
||||
className="select select-sm w-full"
|
||||
value={cred.source}
|
||||
onChange={(e) => onChange({ ...cred, source: e.target.value, keep: false })}
|
||||
>
|
||||
<option value="literal">Plain text</option>
|
||||
<option value="kv">From KV</option>
|
||||
<option value="secret">From secret</option>
|
||||
</select>
|
||||
{cred.source === "literal" ? (
|
||||
<>
|
||||
<div className="flex gap-1 items-center">
|
||||
<input
|
||||
type={masked && !show ? "password" : "text"}
|
||||
className="input input-sm w-full font-mono"
|
||||
value={cred.value}
|
||||
onChange={(e) => onChange({ ...cred, value: e.target.value, keep: false })}
|
||||
placeholder={
|
||||
cred.keep && !cred.value ? "(unchanged — leave blank to keep)" : ""
|
||||
}
|
||||
required={!allowEmpty && !cred.keep && !cred.value}
|
||||
autoComplete="off"
|
||||
/>
|
||||
{masked ? (
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost btn-sm btn-square"
|
||||
title={show ? "Hide" : "Reveal"}
|
||||
aria-label={show ? "Hide value" : "Reveal value"}
|
||||
onClick={() => setShow((v) => !v)}
|
||||
>
|
||||
{show ? <LuEyeOff className="size-4" /> : <LuEye className="size-4" />}
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
{cred.keep && !cred.value ? (
|
||||
<p className="text-xs opacity-60">
|
||||
A value is already set. Enter a new one to replace it.
|
||||
</p>
|
||||
) : null}
|
||||
</>
|
||||
) : null}
|
||||
{cred.source === "kv" ? (
|
||||
<div className="flex flex-col sm:flex-row gap-2">
|
||||
<input
|
||||
className="input input-sm w-full font-mono"
|
||||
placeholder="namespace (optional)"
|
||||
value={cred.namespace}
|
||||
onChange={(e) => onChange({ ...cred, namespace: e.target.value })}
|
||||
/>
|
||||
<input
|
||||
className="input input-sm w-full font-mono"
|
||||
placeholder="key"
|
||||
value={cred.kv}
|
||||
onChange={(e) => onChange({ ...cred, kv: e.target.value })}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
{cred.source === "secret" ? (
|
||||
<>
|
||||
<input
|
||||
className="input input-sm w-full font-mono"
|
||||
placeholder="secret name"
|
||||
value={cred.secret}
|
||||
onChange={(e) => onChange({ ...cred, secret: e.target.value })}
|
||||
required
|
||||
pattern="[A-Za-z0-9._-]+"
|
||||
/>
|
||||
<p className="text-xs opacity-60">
|
||||
Encrypted secret — value is never shown here. Manage it on the Secrets page.
|
||||
</p>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* List cell: literals show *** with reveal; secrets never reveal; kv shows ref only.
|
||||
*/
|
||||
function CredDisplay({ field, fieldKey, authName, cache, onRevealed }) {
|
||||
function CredDisplay({ field, fieldKey, authId, cache, onRevealed }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState(null);
|
||||
@@ -181,7 +34,6 @@ function CredDisplay({ field, fieldKey, authName, cache, onRevealed }) {
|
||||
return <span className="font-mono text-xs">{ref}</span>;
|
||||
}
|
||||
|
||||
// literal
|
||||
const revealed = cache?.[fieldKey];
|
||||
const shown = open && typeof revealed === "string";
|
||||
|
||||
@@ -197,7 +49,7 @@ function CredDisplay({ field, fieldKey, authName, cache, onRevealed }) {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const data = await fetchHttpAuthLiterals(authName);
|
||||
const data = await fetchHttpAuthLiterals(authId);
|
||||
onRevealed?.(data.literals ?? {});
|
||||
setOpen(true);
|
||||
} catch (err) {
|
||||
@@ -241,7 +93,7 @@ function CredentialsCell({ auth, cache, onRevealed }) {
|
||||
<CredDisplay
|
||||
field={cfg.token}
|
||||
fieldKey="token"
|
||||
authName={auth.name}
|
||||
authId={auth.id}
|
||||
cache={cache}
|
||||
onRevealed={onRevealed}
|
||||
/>
|
||||
@@ -255,7 +107,7 @@ function CredentialsCell({ auth, cache, onRevealed }) {
|
||||
<CredDisplay
|
||||
field={cfg.user}
|
||||
fieldKey="user"
|
||||
authName={auth.name}
|
||||
authId={auth.id}
|
||||
cache={cache}
|
||||
onRevealed={onRevealed}
|
||||
/>
|
||||
@@ -265,7 +117,7 @@ function CredentialsCell({ auth, cache, onRevealed }) {
|
||||
<CredDisplay
|
||||
field={cfg.password}
|
||||
fieldKey="password"
|
||||
authName={auth.name}
|
||||
authId={auth.id}
|
||||
cache={cache}
|
||||
onRevealed={onRevealed}
|
||||
/>
|
||||
@@ -279,7 +131,7 @@ function CredentialsCell({ auth, cache, onRevealed }) {
|
||||
<CredDisplay
|
||||
field={cfg.value}
|
||||
fieldKey="value"
|
||||
authName={auth.name}
|
||||
authId={auth.id}
|
||||
cache={cache}
|
||||
onRevealed={onRevealed}
|
||||
/>
|
||||
@@ -287,122 +139,70 @@ function CredentialsCell({ auth, cache, onRevealed }) {
|
||||
);
|
||||
}
|
||||
|
||||
const emptyForm = () => ({
|
||||
name: "",
|
||||
type: "bearer",
|
||||
token: emptyCred(),
|
||||
user: emptyCred(),
|
||||
password: emptyCred(),
|
||||
header: "",
|
||||
value: emptyCred(),
|
||||
unauthorized_status: "",
|
||||
unauthorized_response: "",
|
||||
});
|
||||
|
||||
export function AuthProfilesPage() {
|
||||
const navigate = useNavigate();
|
||||
const location = useLocation();
|
||||
const { name: routeName } = useParams();
|
||||
const isNewRoute = /\/auth\/new\/?$/.test(location.pathname);
|
||||
const isEditRoute = Boolean(routeName) && !isNewRoute;
|
||||
|
||||
const { data: auths = [], isLoading } = useHttpAuths();
|
||||
const { data: pages = [] } = useHttpPages();
|
||||
const upsert = useUpsertHttpAuth();
|
||||
const del = useDeleteHttpAuth();
|
||||
const [mode, setMode] = useState(null);
|
||||
const [form, setForm] = useState(emptyForm);
|
||||
const [editor, setEditor] = useState(null);
|
||||
const [confirmDelete, setConfirmDelete] = useState(null);
|
||||
/** @type {[Record<string, Record<string, string>>, Function]} */
|
||||
const [revealCache, setRevealCache] = useState({});
|
||||
const [editLoading, setEditLoading] = useState(false);
|
||||
const openedRouteKey = useRef(null);
|
||||
|
||||
function openAdd() {
|
||||
setMode("add");
|
||||
setForm(emptyForm());
|
||||
}
|
||||
|
||||
async function openEdit(a) {
|
||||
setEditLoading(true);
|
||||
/** @type {Record<string, string>} */
|
||||
let literals = {};
|
||||
try {
|
||||
const data = await fetchHttpAuthLiterals(a.name);
|
||||
literals = data.literals ?? {};
|
||||
setRevealCache((prev) => ({ ...prev, [a.name]: literals }));
|
||||
} catch {
|
||||
// keep empty; form still works with keep markers
|
||||
} finally {
|
||||
setEditLoading(false);
|
||||
function closeEditor() {
|
||||
setEditor(null);
|
||||
openedRouteKey.current = null;
|
||||
if (isNewRoute || isEditRoute) {
|
||||
navigate("/auth", { replace: true });
|
||||
}
|
||||
const cfg = a.config ?? {};
|
||||
setMode("edit");
|
||||
setForm({
|
||||
name: a.name,
|
||||
type: a.type,
|
||||
token: credFromPublic(cfg.token, literals.token),
|
||||
user: credFromPublic(cfg.user, literals.user),
|
||||
password: credFromPublic(cfg.password, literals.password),
|
||||
header: cfg.header ?? "",
|
||||
value: credFromPublic(cfg.value, literals.value),
|
||||
unauthorized_status: a.unauthorized_status ?? "",
|
||||
unauthorized_response: a.unauthorized_response ?? "",
|
||||
});
|
||||
}
|
||||
|
||||
function closeForm() {
|
||||
setMode(null);
|
||||
setForm(emptyForm());
|
||||
}
|
||||
useEffect(() => {
|
||||
if (!isNewRoute) return;
|
||||
if (openedRouteKey.current === "new") return;
|
||||
openedRouteKey.current = "new";
|
||||
setEditor({ mode: "add" });
|
||||
}, [isNewRoute]);
|
||||
|
||||
function onSubmit(e) {
|
||||
e.preventDefault();
|
||||
/** @type {Record<string, unknown>} */
|
||||
let config = {};
|
||||
if (form.type === "bearer") {
|
||||
const token = toApiField(form.token);
|
||||
if (token == null) return;
|
||||
config = { token };
|
||||
} else if (form.type === "basic") {
|
||||
const user = toApiField(form.user);
|
||||
if (user == null) return;
|
||||
const password = toApiField(form.password, { required: false });
|
||||
config = { user, password: password ?? "" };
|
||||
} else {
|
||||
const value = toApiField(form.value);
|
||||
if (value == null) return;
|
||||
config = { header: form.header, value };
|
||||
useEffect(() => {
|
||||
if (!isEditRoute) {
|
||||
if (!isNewRoute) openedRouteKey.current = null;
|
||||
return;
|
||||
}
|
||||
|
||||
upsert.mutate(
|
||||
{
|
||||
name: form.name,
|
||||
type: form.type,
|
||||
config,
|
||||
unauthorized_status:
|
||||
form.unauthorized_status === "" ? null : Number(form.unauthorized_status),
|
||||
unauthorized_response: form.unauthorized_response || null,
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
setRevealCache((prev) => {
|
||||
const next = { ...prev };
|
||||
delete next[form.name];
|
||||
return next;
|
||||
});
|
||||
closeForm();
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
if (isLoading) return;
|
||||
const key = `edit:${routeName}`;
|
||||
if (openedRouteKey.current === key) return;
|
||||
openedRouteKey.current = key;
|
||||
const auth = auths.find((a) => a.name === routeName);
|
||||
if (!auth) {
|
||||
setEditor({ mode: "add" });
|
||||
return;
|
||||
}
|
||||
setEditor({ mode: "edit", auth });
|
||||
}, [isEditRoute, isNewRoute, routeName, isLoading, auths]);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2">
|
||||
<h1 className="text-xl font-semibold">Auth</h1>
|
||||
<button type="button" className="btn btn-primary btn-sm" onClick={openAdd}>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary btn-sm"
|
||||
onClick={() => navigate("/auth/new")}
|
||||
>
|
||||
<LuPlus className="size-4" />
|
||||
Add
|
||||
</button>
|
||||
</div>
|
||||
<p className="text-sm opacity-70">
|
||||
Named HTTP trigger auth profiles. Reference in YAML as{" "}
|
||||
<code className="font-mono text-xs">auth: name</code>. Secrets are managed on the Secrets
|
||||
page; KV values stay in KV.
|
||||
HTTP trigger auth profiles. Rename freely — workflows keep working via a stable id.
|
||||
Add them to a trigger from the workflow editor dropdown. Secrets are managed on the
|
||||
Secrets page; KV values stay in KV.
|
||||
</p>
|
||||
|
||||
{isLoading ? (
|
||||
@@ -429,9 +229,9 @@ export function AuthProfilesPage() {
|
||||
<td>
|
||||
<CredentialsCell
|
||||
auth={a}
|
||||
cache={revealCache[a.name]}
|
||||
cache={revealCache[a.id]}
|
||||
onRevealed={(literals) =>
|
||||
setRevealCache((prev) => ({ ...prev, [a.name]: literals }))
|
||||
setRevealCache((prev) => ({ ...prev, [a.id]: literals }))
|
||||
}
|
||||
/>
|
||||
</td>
|
||||
@@ -441,8 +241,7 @@ export function AuthProfilesPage() {
|
||||
type="button"
|
||||
className="btn btn-ghost btn-xs"
|
||||
title="Edit"
|
||||
disabled={editLoading}
|
||||
onClick={() => openEdit(a)}
|
||||
onClick={() => navigate(`/auth/${encodeURIComponent(a.name)}/edit`)}
|
||||
>
|
||||
<LuPencil className="size-4" />
|
||||
</button>
|
||||
@@ -462,116 +261,21 @@ export function AuthProfilesPage() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{mode ? (
|
||||
<form
|
||||
onSubmit={onSubmit}
|
||||
className="fieldset bg-base-100 border-base-300 rounded-box max-w-xl border p-4 space-y-2"
|
||||
>
|
||||
<div className="flex items-center justify-between">
|
||||
<legend className="fieldset-legend">
|
||||
{mode === "add" ? "New auth profile" : `Edit ${form.name}`}
|
||||
</legend>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost btn-sm btn-square"
|
||||
onClick={closeForm}
|
||||
aria-label="Close"
|
||||
>
|
||||
<LuX className="size-4" />
|
||||
</button>
|
||||
</div>
|
||||
<label className="label">Name</label>
|
||||
<input
|
||||
className="input w-full font-mono"
|
||||
value={form.name}
|
||||
onChange={(e) => setForm({ ...form, name: e.target.value })}
|
||||
required
|
||||
pattern="[A-Za-z0-9._-]+"
|
||||
disabled={mode === "edit"}
|
||||
/>
|
||||
<label className="label">Type</label>
|
||||
<select
|
||||
className="select w-full"
|
||||
value={form.type}
|
||||
onChange={(e) => setForm({ ...form, type: e.target.value })}
|
||||
>
|
||||
<option value="bearer">bearer</option>
|
||||
<option value="basic">basic</option>
|
||||
<option value="header">header</option>
|
||||
</select>
|
||||
|
||||
{form.type === "bearer" ? (
|
||||
<CredentialFields
|
||||
label="Token"
|
||||
cred={form.token}
|
||||
onChange={(token) => setForm({ ...form, token })}
|
||||
/>
|
||||
) : null}
|
||||
{form.type === "basic" ? (
|
||||
<>
|
||||
<CredentialFields
|
||||
label="User"
|
||||
cred={form.user}
|
||||
onChange={(user) => setForm({ ...form, user })}
|
||||
/>
|
||||
<CredentialFields
|
||||
label="Password"
|
||||
cred={form.password}
|
||||
onChange={(password) => setForm({ ...form, password })}
|
||||
allowEmpty
|
||||
masked
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
{form.type === "header" ? (
|
||||
<>
|
||||
<label className="label">Header name</label>
|
||||
<input
|
||||
className="input w-full font-mono"
|
||||
value={form.header}
|
||||
onChange={(e) => setForm({ ...form, header: e.target.value })}
|
||||
required
|
||||
placeholder="X-Webhook-Secret"
|
||||
/>
|
||||
<CredentialFields
|
||||
label="Header value"
|
||||
cred={form.value}
|
||||
onChange={(value) => setForm({ ...form, value })}
|
||||
/>
|
||||
</>
|
||||
) : null}
|
||||
|
||||
<label className="label">Unauthorized status (optional)</label>
|
||||
<input
|
||||
type="number"
|
||||
className="input w-full"
|
||||
value={form.unauthorized_status}
|
||||
onChange={(e) => setForm({ ...form, unauthorized_status: e.target.value })}
|
||||
min={100}
|
||||
max={599}
|
||||
placeholder="401"
|
||||
/>
|
||||
<label className="label">Unauthorized response page (optional)</label>
|
||||
<select
|
||||
className="select w-full"
|
||||
value={form.unauthorized_response}
|
||||
onChange={(e) => setForm({ ...form, unauthorized_response: e.target.value })}
|
||||
>
|
||||
<option value="">(default JSON)</option>
|
||||
{pages.map((p) => (
|
||||
<option key={p.id} value={p.name}>
|
||||
{p.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
{upsert.isError ? (
|
||||
<p className="text-error text-sm">{errorMessage(upsert.error)}</p>
|
||||
) : null}
|
||||
<button type="submit" className="btn btn-primary mt-2" disabled={upsert.isPending}>
|
||||
Save
|
||||
</button>
|
||||
</form>
|
||||
{editor ? (
|
||||
<AuthEditorModal
|
||||
mode={editor.mode}
|
||||
auth={editor.auth}
|
||||
onClose={closeEditor}
|
||||
onSaved={(saved) => {
|
||||
const id = saved?.id || editor.auth?.id;
|
||||
if (!id) return;
|
||||
setRevealCache((prev) => {
|
||||
const next = { ...prev };
|
||||
delete next[id];
|
||||
return next;
|
||||
});
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{confirmDelete ? (
|
||||
|
||||
Reference in New Issue
Block a user