Skip to content

Commit ba14188

Browse files
authored
Fixed issue with sso occasionally hanging (#6076)
* Fixed issue with sso occasionally hanging * linting
1 parent 5ff9fa5 commit ba14188

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

app/javascript/App.jsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// You should have received a copy of the GNU Lesser General Public License along
1515
// with Greenlight; if not, see <http://www.gnu.org/licenses/>.
1616

17-
import React, { useEffect, useRef } from 'react';
17+
import React, { useCallback, useEffect, useState } from 'react';
1818
import { Container, Form, Spinner } from 'react-bootstrap';
1919
import {
2020
Outlet, useLocation, useNavigate, useSearchParams,
@@ -35,7 +35,7 @@ export default function App() {
3535
const [searchParams] = useSearchParams();
3636
const { data: env } = useEnv();
3737
const autoSignIn = searchParams.get('sso');
38-
const formRef = useRef(null);
38+
const [formElement, setFormElement] = useState(null);
3939

4040
// check for the maintenance banner
4141
const maintenanceBanner = useSiteSetting(['Maintenance']);
@@ -58,17 +58,24 @@ export default function App() {
5858
}
5959
}, [maintenanceBanner.data]);
6060

61+
const formRef = useCallback((node) => {
62+
if (node) {
63+
setFormElement(node);
64+
}
65+
}, []);
66+
6167
// Handle sso login through parameter
6268
useEffect(() => {
63-
if (!env || currentUser.signed_in || !autoSignIn) return;
69+
if (autoSignIn && currentUser.signed_in) { navigate('/', { replace: true }); }
70+
if (!env || !autoSignIn || !formElement) return;
6471

6572
if (env.EXTERNAL_AUTH) {
6673
// eslint-disable-next-line no-unused-expressions
67-
formRef.current?.requestSubmit?.() || formRef.current?.submit();
74+
formElement.requestSubmit?.() || formElement.submit();
6875
} else {
6976
navigate('/signin', { replace: true });
7077
}
71-
}, [autoSignIn, env, formRef.current]);
78+
}, [autoSignIn, env, formElement]);
7279

7380
// Pages that do not need a header: SignIn, SignUp and JoinMeeting (if the user is not signed in)
7481
const homePage = location.pathname === '/';

0 commit comments

Comments
 (0)