import Channels, { STORE_ITEMS } from "../../electron/constants"; import { useEffect, useState } from "react"; import { useRecoilState, useSetRecoilState } from "recoil"; import { $jwtToken } from "../../controller/recoil"; import { FcGoogle } from "react-icons/fc"; import Logo from "../../components/Logo"; import { useLogin } from "../../controller/index"; export default function Login() { const { mutateAsync } = useLogin(); const [isLoading, setIsLoading] = useState(false); const setJwtToken = useSetRecoilState($jwtToken); useEffect(() => { window.electronAPI.once( Channels.GOOGLE_AUTH_TOKENS, async (tokens: { access_token: string; id_token: string; refresh_token: string; }) => { console.log("got tokens", tokens); setIsLoading(true); // todo: implement refresh token procedure in api layer by sending refresh_token and such const loginResponse = await mutateAsync({ accessToken: tokens.access_token, idToken: tokens.id_token, }); const { jwtToken, userDetails } = loginResponse; setJwtToken(jwtToken); } ); // todo: figure out how to clean up with the preload api // return () => { // window.electronAPI.removeAllListeners(Channels.GOOGLE_AUTH_TOKENS); // }; }, []); const continueAuth = () => { setIsLoading(true); // send to main process window.electronAPI.auth.initiateLogin(); }; return (
{/* ! TESTING PURPOSES */}
{isLoading ? ( <> Attempting to log you in ) : ( )}
); }