cleaning a bunch of the auth stuff but not done

This commit is contained in:
talksik
2022-04-01 11:10:37 -04:00
parent 95fe01af03
commit 685c03e505
18 changed files with 554 additions and 678 deletions
@@ -1,8 +1,10 @@
import { $authTokens } from "../../controller/recoil";
import Login from "../../pages/Login";
import NirvanaApi from "../../controller/nirvanaApi";
import { STORE_ITEMS } from "../../electron/constants";
import SkeletonLoader from "../loading/skeleton";
import { useEffect } from "react";
import { useGetUserDetails } from "../../controller/index";
import { useLogin } from "../../controller/index";
import { useRecoilValue } from "recoil";
export default function ProtectedRoute({
@@ -10,26 +12,37 @@ export default function ProtectedRoute({
}: {
children?: React.ReactNode;
}) {
const { data, isLoading, isError, refetch } = useGetUserDetails();
const authTokens = useRecoilValue($authTokens);
const { mutateAsync } = useLogin();
useEffect(() => {
if (!authTokens) {
refetch();
}
}, [authTokens]);
// on load of this, if we already have jwt tokens in store,
// then try using them with auth check, and if successful with simple dime call, then let them continue
window.electronAPI.store
.get(STORE_ITEMS.AUTH_SESSION_JWT)
.then((jwtToken: string) => {
if (jwtToken) {
// todo use this to do an auth check...set the necessary things to make react query run the check
// check if the jwt token is good
if (isLoading)
return (
<div className="container h-screen w-screen flex flex-col justify-center mx-10">
<SkeletonLoader />
</div>
);
// then pass onto the api and such
if (isError) {
return <Login onReady={() => refetch()} />;
}
NirvanaApi._jwtToken = jwtToken;
}
});
}, []);
return <Login />;
// if (isLoading || isIdle)
// return (
// <div className="container h-screen w-screen flex flex-col justify-center mx-10">
// <SkeletonLoader />
// </div>
// );
// if (isError) {
// return <Login />;
// }
// if we can successfully get user details, we are good to continue
return <>{children}</>;