improvement(frontend): Update app behavior with invalid tokens (#4286)

This commit is contained in:
sp.wack 2024-10-10 02:14:48 +04:00 committed by GitHub
parent 77772b6954
commit a6993b7bf5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 18 additions and 10 deletions

View File

@ -128,10 +128,10 @@ export default function App() {
}, [user]);
React.useEffect(() => {
// If the user is on the home page, we should stop the socket connection.
// This is relevant when the user redirects here for whatever reason.
if (location.pathname === "/" && isConnected) {
stop();
if (location.pathname === "/") {
// If the user is on the home page, we should stop the socket connection.
// This is relevant when the user redirects here for whatever reason.
if (isConnected) stop();
}
}, [location.pathname]);

View File

@ -72,6 +72,9 @@ function GitHubAuth({
}
export const clientLoader = async ({ request }: ClientLoaderFunctionArgs) => {
const token = localStorage.getItem("token");
if (token) return redirect("/app");
const ghToken = localStorage.getItem("ghToken");
let repositories: GitHubRepository[] = [];
if (ghToken) {

View File

@ -10,6 +10,7 @@ import {
} from "@remix-run/react";
import { useDispatch, useSelector } from "react-redux";
import WebSocket from "ws";
import toast from "react-hot-toast";
import ChatInterface from "#/components/chat/ChatInterface";
import { getSettings } from "#/services/settings";
import Security from "../components/modals/security/Security";
@ -181,6 +182,7 @@ function App() {
}
if ("error" in parsed) {
toast.error(parsed.error);
fetcher.submit({}, { method: "POST", action: "/end-session" });
return;
}

View File

@ -1,11 +1,7 @@
import { redirect } from "@remix-run/react";
import { clearSession } from "#/utils/clear-session";
export const clientAction = () => {
const token = localStorage.getItem("token");
const repo = localStorage.getItem("repo");
if (token) localStorage.removeItem("token");
if (repo) localStorage.removeItem("repo");
clearSession();
return redirect("/");
};

View File

@ -0,0 +1,7 @@
/**
* Clear the session data from the local storage. This will remove the token and repo
*/
export const clearSession = () => {
localStorage.removeItem("token");
localStorage.removeItem("repo");
};