This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch v3-0-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v3-0-test by this push:
     new f44e8baacb1 [v3-0-test] Improve SAM login onSuccess fn (#49866) 
(#50032)
f44e8baacb1 is described below

commit f44e8baacb13cd2534348f80b7f989c841fd6ad8
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Apr 30 19:13:01 2025 +0200

    [v3-0-test] Improve SAM login onSuccess fn (#49866) (#50032)
    
    (cherry picked from commit 2cc3c3428d21e5db2d066c86b313dabb7c8fe6fc)
    
    Co-authored-by: Pierre Jeambrun <[email protected]>
---
 .../api_fastapi/auth/managers/simple/ui/src/login/Login.tsx | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git 
a/airflow-core/src/airflow/api_fastapi/auth/managers/simple/ui/src/login/Login.tsx
 
b/airflow-core/src/airflow/api_fastapi/auth/managers/simple/ui/src/login/Login.tsx
index 34691eacf85..6aa65345361 100644
--- 
a/airflow-core/src/airflow/api_fastapi/auth/managers/simple/ui/src/login/Login.tsx
+++ 
b/airflow-core/src/airflow/api_fastapi/auth/managers/simple/ui/src/login/Login.tsx
@@ -34,8 +34,7 @@ export type LoginBody = {
 
 const isSafeUrl = (targetUrl: string): boolean => {
   try {
-    // eslint-disable-next-line no-restricted-globals
-    const base = new URL(window.location.origin);
+    const base = new URL(globalThis.location.origin);
     const target = new URL(targetUrl, base);
 
     return (target.protocol === "http:" || target.protocol === "https:") && 
target.origin === base.origin;
@@ -54,20 +53,20 @@ export const Login = () => {
   );
 
   const onSuccess = (data: LoginResponse) => {
-    // Redirect to appropriate page with the token
-    const next = searchParams.get("next");
-
     // Fallback similar to FabAuthManager, strip off the next
     const fallback = "/";
 
+    // Redirect to appropriate page with the token
+    const next = searchParams.get("next") ?? fallback;
+
     setCookie("_token", data.access_token, {
       path: "/",
       secure: globalThis.location.protocol !== "http:",
     });
 
-    const redirectTarget = isSafeUrl(next!) ? next : fallback;
+    const redirectTarget = isSafeUrl(next) ? next : fallback;
 
-    globalThis.location.replace(redirectTarget!);
+    globalThis.location.replace(redirectTarget);
   };
   const { createToken, error, isPending, setError } = useCreateToken({
     onSuccess,

Reply via email to