import { useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; import { CircleCheck, LoaderCircle, TriangleAlert } from "lucide-react"; import { postSpotifyExchange } from "../endpoints/spotify-exchange_POST.schema"; import { getDesktopBridge } from "../helpers/desktopBridge"; import styles from "./spotify.callback.module.css"; export default function SpotifyCallbackPage() { const navigate = useNavigate(); const [error, setError] = useState(null); const [handedToApp, setHandedToApp] = useState(false); useEffect(() => { const params = new URLSearchParams(window.location.search); const spotifyError = params.get("error"); const code = params.get("code"); const state = params.get("state"); if (spotifyError) { setError(`Spotify authorization was not completed: ${spotifyError}`); return; } if (!code || !state) { setError("Spotify did not return the expected authorization information."); return; } postSpotifyExchange({ code, state }) .then((result) => { if (result.desktop && !getDesktopBridge()) setHandedToApp(true); else navigate("/", { replace: true }); }) .catch((reason) => setError(reason instanceof Error ? reason.message : "Spotify login failed.")); }, [navigate]); return (
Aurora SpotiRip {error ? (
Spotify connection failed

{error}

) : handedToApp ? (
Spotify connected

Return to Aurora SpotiRip. You can close this tab.

) : (
Connecting Spotify…

Finishing authorization and loading your account.

)}
); }