mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
improvement(frontend): Update app behavior with invalid tokens (#4286)
This commit is contained in:
parent
77772b6954
commit
a6993b7bf5
@ -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]);
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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("/");
|
||||
};
|
||||
|
||||
7
frontend/src/utils/clear-session.ts
Normal file
7
frontend/src/utils/clear-session.ts
Normal 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");
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user