Harden authentication and writable endpoints
This commit is contained in:
parent
c034824338
commit
0a7ee5ff35
33 changed files with 308 additions and 284 deletions
|
|
@ -28,9 +28,6 @@ export default function ConnectKofi({
|
|||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
// if your auth middleware expects anything, set it here; otherwise cookies suffice
|
||||
"x-user-id": userId ?? "",
|
||||
"x-user-email": email ?? "",
|
||||
},
|
||||
credentials: "include",
|
||||
body: JSON.stringify({ email: value }),
|
||||
|
|
@ -68,7 +65,6 @@ export default function ConnectKofi({
|
|||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"x-user-id": userId ?? "",
|
||||
},
|
||||
credentials: "include",
|
||||
});
|
||||
|
|
|
|||
|
|
@ -32,14 +32,7 @@ export default function SupporterBadges({
|
|||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let url = "/api/support/badges";
|
||||
const params = new URLSearchParams();
|
||||
if (email) params.set("email", String(email));
|
||||
if (userId) params.set("userId", String(userId));
|
||||
const qs = params.toString();
|
||||
if (qs) url += `?${qs}`;
|
||||
|
||||
fetch(url, { cache: "no-store" })
|
||||
fetch("/api/support/badges", { cache: "no-store", credentials: "include" })
|
||||
.then((r) => (r.ok ? r.json() : Promise.reject(r)))
|
||||
.then((json) => setBadges(Array.isArray(json?.badges) ? json.badges : []))
|
||||
.catch(async (e) => {
|
||||
|
|
|
|||
23
app/components/common/HighlightText.tsx
Normal file
23
app/components/common/HighlightText.tsx
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { Fragment, type ReactNode } from "react";
|
||||
|
||||
export default function HighlightText({ text, query }: { text: unknown; query: string }): ReactNode {
|
||||
const value = String(text ?? "");
|
||||
if (!query) return value;
|
||||
|
||||
const haystack = value.toLocaleLowerCase();
|
||||
const needle = query.toLocaleLowerCase();
|
||||
if (!needle) return value;
|
||||
|
||||
const parts: ReactNode[] = [];
|
||||
let start = 0;
|
||||
let match = haystack.indexOf(needle, start);
|
||||
while (match !== -1) {
|
||||
if (match > start) parts.push(value.slice(start, match));
|
||||
parts.push(<mark key={`${match}-${parts.length}`}>{value.slice(match, match + query.length)}</mark>);
|
||||
start = match + query.length;
|
||||
match = haystack.indexOf(needle, start);
|
||||
}
|
||||
if (start < value.length) parts.push(value.slice(start));
|
||||
|
||||
return <Fragment>{parts.length ? parts : value}</Fragment>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue