import { Loader } from "@mantine/core";
import { useEffect } from "react";
import { useSearchParams } from "react-router";

export function Login() {
    const [searchParams] = useSearchParams();

    useEffect(() => {
        const accessToken = searchParams.get("access_token");
        const idToken = searchParams.get("id_token");
        const refreshToken = searchParams.get("refresh_token");

        if (accessToken && idToken) {
            localStorage.setItem("access_token", accessToken);
            localStorage.setItem("id_token", idToken);
            localStorage.setItem("refresh_token", refreshToken || "");
            window.location.href = "/";
        }
    }, [searchParams]);

    return <Loader />;
}
