Skip to content

πŸ™Œ OpenHands: AI-Driven Development

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

sp.wacka6993b7bf58e
diff --git a/frontend/src/root.tsx b/frontend/src/root.tsx
index 82dc29b54e..26a8d2e301 100644
--- a/frontend/src/root.tsx
+++ b/frontend/src/root.tsx
@@ -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]);
diff --git a/frontend/src/routes/_index/route.tsx b/frontend/src/routes/_index/route.tsx
index a8c809527f..a64deb3ddc 100644
--- a/frontend/src/routes/_index/route.tsx
+++ b/frontend/src/routes/_index/route.tsx
@@ -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) {
diff --git a/frontend/src/routes/app.tsx b/frontend/src/routes/app.tsx
index f3536b546b..31b196b0c9 100644
--- a/frontend/src/routes/app.tsx
+++ b/frontend/src/routes/app.tsx
@@ -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;
}
diff --git a/frontend/src/routes/end-session.ts b/frontend/src/routes/end-session.ts
index 2fedad99f2..bfaed749c7 100644
--- a/frontend/src/routes/end-session.ts
+++ b/frontend/src/routes/end-session.ts
@@ -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("/");
};
diff --git a/frontend/src/utils/clear-session.ts b/frontend/src/utils/clear-session.ts
new file mode 100644
index 0000000000..27013c31b5
--- /dev/null
+++ b/frontend/src/utils/clear-session.ts
@@ -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");
+};