interim auth fix

This commit is contained in:
talksik
2022-03-18 21:57:23 -04:00
parent b5a5c9b644
commit 3bf3c586d1
2 changed files with 31 additions and 19 deletions
@@ -13,3 +13,8 @@ export const $searchQuery = atom<string>({
key: "SEARCH_QUERY", key: "SEARCH_QUERY",
default: "", default: "",
}); });
export const $authFailureCount = atom<number>({
key: "AUTH_FAILURE_COUNT",
default: 0,
});
+12 -5
View File
@@ -1,17 +1,19 @@
import { $authFailureCount, $authTokens } from "../../controller/recoil";
import Channels, { STORE_ITEMS } from "../../electron/constants"; import Channels, { STORE_ITEMS } from "../../electron/constants";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useRecoilState, useSetRecoilState } from "recoil";
import { $authTokens } from "../../controller/recoil";
import { CircularProgress } from "@mui/material"; import { CircularProgress } from "@mui/material";
import { FcGoogle } from "react-icons/fc"; import { FcGoogle } from "react-icons/fc";
import Logo from "../../components/Logo"; import Logo from "../../components/Logo";
import { nirvanaApi } from "../../controller/nirvanaApi"; import { nirvanaApi } from "../../controller/nirvanaApi";
import { useCreateUser } from "../../controller/index"; import { useCreateUser } from "../../controller/index";
import { useSetRecoilState } from "recoil";
export default function Login({ onReady }: { onReady: Function }) { export default function Login({ onReady }: { onReady: Function }) {
const setAuthTokens = useSetRecoilState($authTokens); const setAuthTokens = useSetRecoilState($authTokens);
const [isLoading, setIsLoading] = useState<boolean>(false); const [isLoading, setIsLoading] = useState<boolean>(false);
const [authFailureCount, setAuthFailureCount] =
useRecoilState($authFailureCount);
const continueAuth = () => { const continueAuth = () => {
setIsLoading(true); setIsLoading(true);
@@ -37,10 +39,14 @@ export default function Login({ onReady }: { onReady: Function }) {
}; };
useEffect(() => { useEffect(() => {
// todo make sure we don't loop flash when id token expires for user // todo solve this better by just using refresh token in the backend
// hack for now log out in this case
// logOut();
setAuthFailureCount((prevVal) => prevVal + 1);
// if failure count is 2, then just log the user out
if (authFailureCount >= 2) {
logOut();
} else {
// see if we have tokens in localstorage in which case we can continue on // see if we have tokens in localstorage in which case we can continue on
window.electronAPI.store window.electronAPI.store
.get(STORE_ITEMS.AUTH_TOKENS) .get(STORE_ITEMS.AUTH_TOKENS)
@@ -57,6 +63,7 @@ export default function Login({ onReady }: { onReady: Function }) {
}); });
} }
}); });
}
window.electronAPI.once(Channels.AUTH_TOKENS, (tokens: any) => { window.electronAPI.once(Channels.AUTH_TOKENS, (tokens: any) => {
setIsLoading(true); setIsLoading(true);