Browse Source

allow resource redirect if host is same

Milo Schwartz 6 months ago
parent
commit
c3d19454f7
2 changed files with 11 additions and 12 deletions
  1. 1 2
      server/routers/badger/verifySession.ts
  2. 10 10
      src/app/auth/resource/[resourceId]/page.tsx

+ 1 - 2
server/routers/badger/verifySession.ts

@@ -101,8 +101,7 @@ export async function verifyResourceSession(
             return allowed(res);
         }
 
-        // const redirectUrl = `${config.getRawConfig().app.dashboard_url}/auth/resource/${encodeURIComponent(resource.resourceId)}?redirect=${encodeURIComponent(originalRequestURL)}`;
-        const redirectUrl = `${config.getRawConfig().app.dashboard_url}/auth/resource/${encodeURIComponent(resource.resourceId)}`;
+        const redirectUrl = `${config.getRawConfig().app.dashboard_url}/auth/resource/${encodeURIComponent(resource.resourceId)}?redirect=${encodeURIComponent(originalRequestURL)}`;
 
         if (!sessions) {
             return notAllowed(res);

+ 10 - 10
src/app/auth/resource/[resourceId]/page.tsx

@@ -56,16 +56,16 @@ export default async function ResourceAuthPage(props: {
     }
 
     let redirectUrl = authInfo.url;
-    // if (searchParams.redirect) {
-    //     try {
-    //         const serverResourceHost = new URL(authInfo.url).host;
-    //         const redirectHost = new URL(searchParams.redirect).host;
-    //
-    //         if (serverResourceHost === redirectHost) {
-    //             redirectUrl = searchParams.redirect;
-    //         }
-    //     } catch (e) {}
-    // }
+    if (searchParams.redirect) {
+        try {
+            const serverResourceHost = new URL(authInfo.url).host;
+            const redirectHost = new URL(searchParams.redirect).host;
+
+            if (serverResourceHost === redirectHost) {
+                redirectUrl = searchParams.redirect;
+            }
+        } catch (e) {}
+    }
 
     const hasAuth =
         authInfo.password ||