From faeb2e5b7be6603079c57a6e4b6bdeec964ce130 Mon Sep 17 00:00:00 2001 From: Axel Bocciarelli Date: Mon, 25 Nov 2024 14:04:33 +0100 Subject: [PATCH] Refactor `LoginForm` for SSO login --- ui/src/actions/login.js | 13 +- ui/src/api/login.js | 4 - ui/src/components/LoginForm/LoginForm.jsx | 146 +++++++++++----------- 3 files changed, 73 insertions(+), 90 deletions(-) diff --git a/ui/src/actions/login.js b/ui/src/actions/login.js index 826baa56b..5ae2fe7fc 100644 --- a/ui/src/actions/login.js +++ b/ui/src/actions/login.js @@ -7,12 +7,7 @@ import { fetchAvailableWorkflows } from '../api/workflow'; import { fetchAvailableTasks, fetchQueueState } from '../api/queue'; import { showErrorPanel, applicationFetched } from './general'; -import { - fetchLoginInfo, - sendLogIn, - sendSignOut, - sendSSOLogIn, -} from '../api/login'; +import { fetchLoginInfo, sendLogIn, sendSignOut } from '../api/login'; import { fetchDetectorInfo } from '../api/detector'; import { fetchSampleChangerInitialState } from '../api/sampleChanger'; import { fetchHarvesterInitialState } from '../api/harvester'; @@ -91,12 +86,6 @@ export function logIn(proposal, password) { }; } -export function ssoLogIn() { - return (dispatch) => { - sendSSOLogIn(); - }; -} - export function signOut() { return async (dispatch) => { dispatch(resetLoginInfo()); // disconnect sockets before actually logging out (cf. `App.jsx`) diff --git a/ui/src/api/login.js b/ui/src/api/login.js index 47a08668c..9c9bc97ed 100644 --- a/ui/src/api/login.js +++ b/ui/src/api/login.js @@ -6,10 +6,6 @@ export function sendLogIn(proposal, password, previousUser) { return endpoint.post({ proposal, password, previousUser }, '/').safeJson(); } -export function sendSSOLogIn() { - window.location = 'mxcube/api/v0.1/login/ssologin'; -} - export function sendSignOut() { return endpoint.headers({ Accept: '*/*' }).get('/signout').res(); } diff --git a/ui/src/components/LoginForm/LoginForm.jsx b/ui/src/components/LoginForm/LoginForm.jsx index 53e603523..a37220bfb 100644 --- a/ui/src/components/LoginForm/LoginForm.jsx +++ b/ui/src/components/LoginForm/LoginForm.jsx @@ -7,7 +7,9 @@ import logo from '../../img/mxcube_logo20.png'; import loader from '../../img/loader.gif'; import styles from './LoginForm.module.css'; import { useDispatch, useSelector } from 'react-redux'; -import { logIn, ssoLogIn } from '../../actions/login'; +import { logIn } from '../../actions/login'; + +const SSO_PATH = '/mxcube/api/v0.1/login/ssologin'; function LoginForm() { const dispatch = useDispatch(); @@ -26,6 +28,11 @@ function LoginForm() { const useSSO = useSelector((state) => state.login.useSSO); async function handleSubmit(data) { + if (useSSO) { + window.location.assign(SSO_PATH); + return; + } + setLoading(true); try { await dispatch(logIn(data.username.toLowerCase(), data.password)); @@ -34,10 +41,6 @@ function LoginForm() { } } - async function handleSingleSignOn() { - await dispatch(ssoLogIn()); - } - return (
- {!useSSO && [ - - - - - - ( - + {!useSSO && ( + <> + + + + + + ( + + )} + /> + {errors.username && ( + + {errors.username.message} + )} - /> - {errors.username && ( - - {errors.username.message} - - )} - - , - - - - - - ( - + + + + + + + + ( + + )} + /> + {errors.password && ( + + {errors.password.message} + )} - /> - {errors.password && ( - - {errors.password.message} - - )} - - , - ]} - {useSSO ? ( - - ) : ( - + + + )} + + + {!loading && showErrorPanel && (
{errorMessage}