π OpenHands: AI-Driven Development
Fix so redirect URL is in OAuth state (#8653)
chuckbutkus92f80615582b
diff --git a/frontend/src/hooks/use-auto-login.ts b/frontend/src/hooks/use-auto-login.tsindex 18602cf6e2..b1f35d7468 100644--- a/frontend/src/hooks/use-auto-login.ts+++ b/frontend/src/hooks/use-auto-login.ts@@ -1,12 +1,7 @@import { useEffect } from "react";-import { useNavigate } from "react-router";import { useConfig } from "./query/use-config";import { useIsAuthed } from "./query/use-is-authed";-import {- getLoginMethod,- getLastPage,- LoginMethod,-} from "#/utils/local-storage";+import { getLoginMethod, LoginMethod } from "#/utils/local-storage";import { useAuthUrl } from "./use-auth-url";/**@@ -14,7 +9,6 @@ import { useAuthUrl } from "./use-auth-url";* Only works in SAAS mode and when the user is not already logged in*/export const useAutoLogin = () => {- const navigate = useNavigate();const { data: config, isLoading: isConfigLoading } = useConfig();const { data: isAuthed, isLoading: isAuthLoading } = useIsAuthed();@@ -71,30 +65,4 @@ export const useAutoLogin = () => {githubAuthUrl,gitlabAuthUrl,]);-- // Handle navigation to last page after login- useEffect(() => {- // Only navigate in SAAS mode- if (config?.APP_MODE !== "saas") {- return;- }-- // Wait for auth to load- if (isAuthLoading) {- return;- }-- // Only navigate if authenticated- if (!isAuthed) {- return;- }-- // Get the last page from local storage- const lastPage = getLastPage();-- // Navigate to the last page if it exists- if (lastPage) {- navigate(lastPage);- }- }, [config?.APP_MODE, isAuthed, isAuthLoading, navigate]);};diff --git a/frontend/src/hooks/use-track-last-page.ts b/frontend/src/hooks/use-track-last-page.tsdeleted file mode 100644index 5398c6e3b1..0000000000--- a/frontend/src/hooks/use-track-last-page.ts+++ /dev/null@@ -1,33 +0,0 @@-import { useEffect } from "react";-import { useLocation } from "react-router";-import { useConfig } from "./query/use-config";-import { setLastPage, shouldExcludePath } from "#/utils/local-storage";-import { useIsAuthed } from "./query/use-is-authed";--/**- * Hook to track the last visited page in local storage- * Only tracks pages in SAAS mode and excludes certain paths- */-export const useTrackLastPage = () => {- const location = useLocation();- const { data: config } = useConfig();- const { data: isAuthed, isLoading: isAuthLoading } = useIsAuthed();-- useEffect(() => {- // Only track pages in SAAS mode when authenticated- if (config?.APP_MODE !== "saas" || !isAuthed || isAuthLoading) {- return;- }-- const { pathname } = location;-- // Don't track excluded paths- if (shouldExcludePath(pathname)) {- // leave code block for now as we may decide not to track certain pages.- // return;- }-- // Store the current path as the last visited page- setLastPage(pathname);- }, [location, config?.APP_MODE]);-};diff --git a/frontend/src/routes/root-layout.tsx b/frontend/src/routes/root-layout.tsxindex 76d06de2ef..fb792fb98c 100644--- a/frontend/src/routes/root-layout.tsx+++ b/frontend/src/routes/root-layout.tsx@@ -22,7 +22,6 @@ import { useBalance } from "#/hooks/query/use-balance";import { SetupPaymentModal } from "#/components/features/payment/setup-payment-modal";import { displaySuccessToast } from "#/utils/custom-toast-handlers";import { useIsOnTosPage } from "#/hooks/use-is-on-tos-page";-import { useTrackLastPage } from "#/hooks/use-track-last-page";import { useAutoLogin } from "#/hooks/use-auto-login";import { LOCAL_STORAGE_KEYS } from "#/utils/local-storage";@@ -86,9 +85,6 @@ export default function MainApp() {const [consentFormIsOpen, setConsentFormIsOpen] = React.useState(false);- // Track the last visited page- useTrackLastPage();-// Auto-login if login method is stored in local storageuseAutoLogin();diff --git a/frontend/src/utils/generate-auth-url.ts b/frontend/src/utils/generate-auth-url.tsindex 58051d3424..4876383638 100644--- a/frontend/src/utils/generate-auth-url.ts+++ b/frontend/src/utils/generate-auth-url.ts@@ -16,5 +16,5 @@ export const generateAuthUrl = (identityProvider: string, requestUrl: URL) => {authUrl = `auth.${requestUrl.hostname}`;}const scope = "openid email profile"; // OAuth scope - not user-facing- return `https://${authUrl}/realms/allhands/protocol/openid-connect/auth?client_id=allhands&kc_idp_hint=${identityProvider}&response_type=code&redirect_uri=${encodeURIComponent(redirectUri)}&scope=${encodeURIComponent(scope)}`;+ return `https://${authUrl}/realms/allhands/protocol/openid-connect/auth?client_id=allhands&kc_idp_hint=${identityProvider}&response_type=code&redirect_uri=${encodeURIComponent(redirectUri)}&scope=${encodeURIComponent(scope)}&state=${encodeURIComponent(requestUrl.href)}`;};diff --git a/frontend/src/utils/local-storage.ts b/frontend/src/utils/local-storage.tsindex cfe0757cb8..b5ad0dfc58 100644--- a/frontend/src/utils/local-storage.ts+++ b/frontend/src/utils/local-storage.ts@@ -1,7 +1,6 @@// Local storage keysexport const LOCAL_STORAGE_KEYS = {LOGIN_METHOD: "openhands_login_method",- LAST_PAGE: "openhands_last_page",};// Login methods@@ -27,33 +26,9 @@ export const getLoginMethod = (): LoginMethod | null => {return method as LoginMethod | null;};-/**- * Set the last visited page in local storage- * @param path The path of the last visited page- */-export const setLastPage = (path: string): void => {- localStorage.setItem(LOCAL_STORAGE_KEYS.LAST_PAGE, path);-};--/**- * Get the last visited page from local storage- * @returns The last visited page or null if not set- */-export const getLastPage = (): string | null =>- localStorage.getItem(LOCAL_STORAGE_KEYS.LAST_PAGE);-/*** Clear login method and last page from local storage*/export const clearLoginData = (): void => {localStorage.removeItem(LOCAL_STORAGE_KEYS.LOGIN_METHOD);- localStorage.removeItem(LOCAL_STORAGE_KEYS.LAST_PAGE);};--/**- * Check if the given path should be excluded from being saved as the last page- * @param path The path to check- * @returns True if the path should be excluded, false otherwise- */-export const shouldExcludePath = (path: string): boolean =>- path.startsWith("/settings");