Skip to content

Commit 2ee75a6

Browse files
committed
Claude suggestions: Strip token from URL to avoid failure on reload; Ref to avoid the double load in dev
1 parent 041ff4a commit 2ee75a6

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

apps/website/app/components/auth/LoginWithToken.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22

33
import { createClient } from "~/utils/supabase/client";
44
import { useRouter, useSearchParams } from "next/navigation";
5-
import { useState, useEffect, useCallback } from "react";
5+
import { useState, useEffect, useCallback, useRef } from "react";
66

77
export const LoginWithToken = () => {
8+
const loginAttempted = useRef(false);
89
const searchParams = useSearchParams();
910
const router = useRouter();
10-
const [secretToken] = useState(searchParams.get("t"));
11+
const [secretToken] = useState(() => {
12+
const t = searchParams.get("t");
13+
if (t && typeof window !== "undefined") {
14+
const url = new URL(window.location.href);
15+
url.searchParams.delete("t");
16+
window.history.replaceState({}, "", url);
17+
}
18+
return t;
19+
});
1120
const [url] = useState(searchParams.get("url"));
1221
const [done, setDone] = useState(false);
1322
const [error, setError] = useState<string | null>(
@@ -62,7 +71,8 @@ export const LoginWithToken = () => {
6271
}
6372
}, [secretToken, url, router]);
6473
useEffect(() => {
65-
if (!error && !done) {
74+
if (!error && !done && !loginAttempted.current) {
75+
loginAttempted.current = true;
6676
void login();
6777
}
6878
}, [error, login, secretToken, done]);

0 commit comments

Comments
 (0)