import React, { useEffect, useContext } from "react";
import { UserManager } from "oidc-client-ts";
import { ConfigContext } from "../../ConfigProvider";
import { Spinner } from "../ui/misc";

const SilentCallback = () => {
    const { config } = useContext(ConfigContext);

    useEffect(() => {
        const userManager = new UserManager(config.OIDC_CONFIG);
        userManager.signinSilentCallback()
            .then(() => {
            })
            .catch((err) => {
                console.error("Silent callback error:", err);
            });
    }, [config]);

    return (
        <div className="flex min-h-screen items-center justify-center">
            <Spinner label="Renewing session" />
        </div>
    );
};

export default SilentCallback;