CS4610-FinalProject / FinalProject / src / pages / TestPage.tsx
TestPage.tsx
Raw
import { useContext, useEffect } from "react";
import { useLocation, useNavigate, useParams } from "react-router-dom";
import { ApiContext } from "../contexts/api";
import { useApi } from "../hooks/useApi";

export const Test = () => {
    const navigate = useNavigate();
    const api = useApi();

    const location = useLocation();
    const queryParams = new URLSearchParams(location.search);
    const code = queryParams.get('code');
    

    useEffect(() => {
        if (window.localStorage.getItem('token') !== null) {
            console.log("Token exists, letting api call pass through to prevent redirect errors for async")
        }

        api.getSpotifyToken(code).then(() => {
            window.location.href = "https://cs4610-finalproject.web.app/#/home/";
            // navigate('../home/', { replace: true });
        });
    }, []);

    return (
        <div>
            <h1>Error signing in to Spotify!</h1>
        </div>
    )
}