aboutsummaryrefslogtreecommitdiff
path: root/jb-ui/src/pages/MagicLink.tsx
diff options
context:
space:
mode:
authorMax Nanis2026-09-10 17:46:41 -0700
committerMax Nanis2026-09-10 17:46:41 -0700
commited201936813d9a720b51e6cb40a05267b94e7314 (patch)
treef675f6a0d91ed1d17f654e40936e8c1ca9ccf141 /jb-ui/src/pages/MagicLink.tsx
parent0ac38066402762dc5fa24f2ffa2170681a6eddb1 (diff)
downloadamt-jb-ed201936813d9a720b51e6cb40a05267b94e7314.tar.gz
amt-jb-ed201936813d9a720b51e6cb40a05267b94e7314.zip
Typescript prettier
Committing seperate so it's easier to see actual changes.
Diffstat (limited to 'jb-ui/src/pages/MagicLink.tsx')
-rw-r--r--jb-ui/src/pages/MagicLink.tsx72
1 files changed, 37 insertions, 35 deletions
diff --git a/jb-ui/src/pages/MagicLink.tsx b/jb-ui/src/pages/MagicLink.tsx
index 4042624..eb272a6 100644
--- a/jb-ui/src/pages/MagicLink.tsx
+++ b/jb-ui/src/pages/MagicLink.tsx
@@ -3,42 +3,44 @@ import { useEffect, useRef, useState } from "react";
type ExchangeState = "working" | "failed" | "missing";
const MagicLink = function () {
- const started = useRef(false);
- const [state, setState] = useState<ExchangeState>("working");
-
- useEffect(() => {
- // React Strict Mode runs effects twice in development. Never redeem twice.
- if (started.current) return;
- started.current = true;
-
- const params = new URLSearchParams(window.location.search);
- const token = params.get("token");
- if (!token) {
- setState("missing");
- return;
- }
-
- // Keep the credential out of browser history and subsequent Referer headers.
- window.history.replaceState({}, "", window.location.pathname);
-
- void fetch("/auth/magic-link/exchange", {
- method: "POST",
- credentials: "include",
- headers: {"Content-Type": "application/json"},
- body: JSON.stringify({"token": token}),
- }).then((response) => {
- if (!response.ok) throw new Error("Magic-link exchange failed");
- window.location.replace("/");
- }).catch(() => setState("failed"));
- }, []);
-
- if (state === "missing") {
- return <p>This login link is missing its token.</p>;
+ const started = useRef(false);
+ const [state, setState] = useState<ExchangeState>("working");
+
+ useEffect(() => {
+ // React Strict Mode runs effects twice in development. Never redeem twice.
+ if (started.current) return;
+ started.current = true;
+
+ const params = new URLSearchParams(window.location.search);
+ const token = params.get("token");
+ if (!token) {
+ setState("missing");
+ return;
}
- if (state === "failed") {
- return <p>This login link is invalid or has expired.</p>;
- }
- return <p>Signing you in…</p>;
+
+ // Keep the credential out of browser history and subsequent Referer headers.
+ window.history.replaceState({}, "", window.location.pathname);
+
+ void fetch("/auth/magic-link/exchange", {
+ method: "POST",
+ credentials: "include",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ token: token }),
+ })
+ .then((response) => {
+ if (!response.ok) throw new Error("Magic-link exchange failed");
+ window.location.replace("/");
+ })
+ .catch(() => setState("failed"));
+ }, []);
+
+ if (state === "missing") {
+ return <p>This login link is missing its token.</p>;
+ }
+ if (state === "failed") {
+ return <p>This login link is invalid or has expired.</p>;
+ }
+ return <p>Signing you in…</p>;
};
export default MagicLink;