Browse Source

fix(superuser): Redirect if there is a invalid SSO session error for su access form (#33812)

Richard Ma 2 years ago
parent
commit
a589d66fdb

+ 16 - 0
static/app/components/modals/sudoModal.tsx

@@ -2,6 +2,7 @@ import * as React from 'react';
 import {withRouter, WithRouterProps} from 'react-router';
 import {withRouter, WithRouterProps} from 'react-router';
 import styled from '@emotion/styled';
 import styled from '@emotion/styled';
 
 
+import {logout} from 'sentry/actionCreators/account';
 import {ModalRenderProps} from 'sentry/actionCreators/modal';
 import {ModalRenderProps} from 'sentry/actionCreators/modal';
 import {Client} from 'sentry/api';
 import {Client} from 'sentry/api';
 import Alert from 'sentry/components/alert';
 import Alert from 'sentry/components/alert';
@@ -133,6 +134,16 @@ class SudoModal extends React.Component<Props, State> {
     }
     }
   };
   };
 
 
+  handleLogout = async () => {
+    const {api} = this.props;
+    try {
+      await logout(api);
+    } catch {
+      // ignore errors
+    }
+    window.location.assign('/auth/login/');
+  };
+
   async getAuthenticators() {
   async getAuthenticators() {
     const {api} = this.props;
     const {api} = this.props;
 
 
@@ -150,6 +161,11 @@ class SudoModal extends React.Component<Props, State> {
     const user = ConfigStore.get('user');
     const user = ConfigStore.get('user');
     const isSelfHosted = ConfigStore.get('isSelfHosted');
     const isSelfHosted = ConfigStore.get('isSelfHosted');
 
 
+    if (errorType === ErrorCodes.invalidSSOSession) {
+      this.handleLogout();
+      return null;
+    }
+
     if (
     if (
       (!user.hasPasswordAuth && authenticators.length === 0) ||
       (!user.hasPasswordAuth && authenticators.length === 0) ||
       (isSuperuser && !isSelfHosted)
       (isSuperuser && !isSelfHosted)

+ 15 - 0
static/app/components/superuserAccessForm.tsx

@@ -1,6 +1,7 @@
 import {Component} from 'react';
 import {Component} from 'react';
 import styled from '@emotion/styled';
 import styled from '@emotion/styled';
 
 
+import {logout} from 'sentry/actionCreators/account';
 import {Client} from 'sentry/api';
 import {Client} from 'sentry/api';
 import Alert from 'sentry/components/alert';
 import Alert from 'sentry/components/alert';
 import Form from 'sentry/components/forms/form';
 import Form from 'sentry/components/forms/form';
@@ -64,8 +65,22 @@ class SuperuserAccessForm extends Component<Props, State> {
     });
     });
   };
   };
 
 
+  handleLogout = async () => {
+    const {api} = this.props;
+    try {
+      await logout(api);
+    } catch {
+      // ignore errors
+    }
+    window.location.assign('/auth/login/');
+  };
+
   render() {
   render() {
     const {error, errorType} = this.state;
     const {error, errorType} = this.state;
+    if (errorType === ErrorCodes.invalidSSOSession) {
+      this.handleLogout();
+      return null;
+    }
     return (
     return (
       <ThemeAndStyleProvider>
       <ThemeAndStyleProvider>
         <Form
         <Form