Spaces:
Runtime error
Runtime error
Download frontend/src/pages/AuthCallback.tsx from firebird-technologies/NoteStack-Test: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/spaces/firebird-technologies/NoteStack-Test/resolve/main/frontend/src/pages/AuthCallback.tsx
- Command line
-
hf download hf://spaces/firebird-technologies/NoteStack-Test/frontend/src/pages/AuthCallback.tsx
-
curl -L -o AuthCallback.tsx https://huggingface.co/spaces/firebird-technologies/NoteStack-Test/resolve/main/frontend/src/pages/AuthCallback.tsx
1.45 kB
| import { useEffect, useRef } from "react"; | |
| import { useNavigate } from "react-router-dom"; | |
| import { authApi, safeNext } from "../api/auth"; | |
| import { useAuth } from "../hooks/useAuth"; | |
| /** Landing spot for the Google redirect flow: swaps the one minute ticket in the URL fragment for a session. */ | |
| export default function AuthCallback() { | |
| const { complete } = useAuth(); | |
| const navigate = useNavigate(); | |
| const started = useRef(false); | |
| useEffect(() => { | |
| if (started.current) return; // StrictMode runs effects twice; redeem once | |
| started.current = true; | |
| const fragment = new URLSearchParams(window.location.hash.slice(1)); | |
| const ticket = fragment.get("ticket"); | |
| const next = safeNext(fragment.get("next")); | |
| window.history.replaceState(null, "", window.location.pathname); // keep the ticket out of history | |
| if (!ticket) { | |
| navigate("/auth", { replace: true }); | |
| return; | |
| } | |
| authApi | |
| .redeemTicket(ticket) | |
| .then((result) => { | |
| complete(result); | |
| navigate(result.created && !next.startsWith("/tools/") ? "/welcome" : next, { replace: true }); | |
| }) | |
| .catch(() => { | |
| const error = new URLSearchParams({ error: "Google sign in expired. Try again." }); | |
| navigate(`/auth#${error}`, { replace: true }); | |
| }); | |
| }, [complete, navigate]); | |
| return ( | |
| <div className="boot"> | |
| <div className="orbit-loader"> | |
| <span /> | |
| </div> | |
| </div> | |
| ); | |
| } | |