Browse Source

fix(hybrid-cloud): Update re-authentication logic for superuser/sudo modal forms (#44916)

Alberto Leal 2 years ago
parent
commit
88433211fb

+ 9 - 1
static/app/components/modals/sudoModal.tsx

@@ -1,6 +1,7 @@
 import {Component, Fragment} from 'react';
 import {WithRouterProps} from 'react-router';
 import styled from '@emotion/styled';
+import trimEnd from 'lodash/trimEnd';
 
 import {logout} from 'sentry/actionCreators/account';
 import {ModalRenderProps} from 'sentry/actionCreators/modal';
@@ -174,7 +175,14 @@ class SudoModal extends Component<Props, State> {
     } catch {
       // ignore errors
     }
-    window.location.assign(`/auth/login/?next=${encodeURIComponent(location.pathname)}`);
+    const authLoginPath = `/auth/login/?next=${encodeURIComponent(window.location.href)}`;
+    const {superuserUrl} = window.__initialData.links;
+    if (window.__initialData?.customerDomain && superuserUrl) {
+      const redirectURL = `${trimEnd(superuserUrl, '/')}${authLoginPath}`;
+      window.location.assign(redirectURL);
+      return;
+    }
+    window.location.assign(authLoginPath);
   };
 
   async getAuthenticators() {

+ 9 - 1
static/app/components/superuserAccessForm.tsx

@@ -1,5 +1,6 @@
 import {Component} from 'react';
 import styled from '@emotion/styled';
+import trimEnd from 'lodash/trimEnd';
 
 import {logout} from 'sentry/actionCreators/account';
 import {Client} from 'sentry/api';
@@ -132,7 +133,14 @@ class SuperuserAccessForm extends Component<Props, State> {
     } catch {
       // ignore errors
     }
-    window.location.assign('/auth/login/');
+    const authLoginPath = `/auth/login/?next=${encodeURIComponent(window.location.href)}`;
+    const {superuserUrl} = window.__initialData.links;
+    if (window.__initialData?.customerDomain && superuserUrl) {
+      const redirectURL = `${trimEnd(superuserUrl, '/')}${authLoginPath}`;
+      window.location.assign(redirectURL);
+      return;
+    }
+    window.location.assign(authLoginPath);
   };
 
   async getAuthenticators() {

+ 1 - 0
static/app/types/system.tsx

@@ -142,6 +142,7 @@ export interface Config {
     organizationUrl: string | undefined;
     regionUrl: string | undefined;
     sentryUrl: string;
+    superuserUrl?: string;
   };
   /**
    * This comes from django (django.contrib.messages)