diff --git a/cmd/ui/src/views/Login.tsx b/cmd/ui/src/views/Login.tsx index a7c831872..ee9a978e5 100644 --- a/cmd/ui/src/views/Login.tsx +++ b/cmd/ui/src/views/Login.tsx @@ -16,11 +16,10 @@ import React, { useEffect, useState } from 'react'; import { Navigate } from 'react-router-dom'; -import LoginForm from 'src/components/LoginForm'; import LoginPage from 'src/components/LoginPage'; import { useQuery, useQueryClient } from 'react-query'; import { Box, CircularProgress } from '@mui/material'; -import { OneTimePasscodeForm, LoginViaSSOForm, apiClient } from 'bh-shared-ui'; +import { OneTimePasscodeForm, LoginViaSSOForm, LoginForm, apiClient } from 'bh-shared-ui'; import { login as loginAction, logout } from 'src/ducks/auth/authSlice'; import { ROUTE_HOME, ROUTE_USER_DISABLED } from 'src/ducks/global/routes'; @@ -67,8 +66,8 @@ const Login: React.FC = () => { dispatch(loginAction({ username: lastUsername, password: lastPassword, otp })); }; - const handleSubmitLoginViaSSOForm = (redirectURL: string) => { - window.location.assign(redirectURL); + const handleSubmitLoginViaSSOForm = (providerSlug: string) => { + window.location.assign(`/api/v2/sso/${providerSlug}/login`); }; /* Implementation */ @@ -113,6 +112,10 @@ const Login: React.FC = () => { } if (useSSO) { + if (listSSOProvidersQuery.data?.length === 1) { + handleSubmitLoginViaSSOForm(listSSOProvidersQuery.data[0].slug); + return; + } return ( { await user.click(screen.getByText(testSSOProviders[0].name)); expect(screen.getByRole('button', { name: /continue$/i })).not.toBeDisabled(); await user.click(screen.getByRole('button', { name: /continue$/i })); - expect(testOnSubmit).toHaveBeenCalledWith(`/api/v2/sso/${testSSOProviders[0].slug}/login`); + expect(testOnSubmit).toHaveBeenCalledWith(testSSOProviders[0].slug); }); it('should call onCancel when cancel button clicked', async () => { diff --git a/packages/javascript/bh-shared-ui/src/components/LoginViaSSOForm/LoginViaSSOForm.tsx b/packages/javascript/bh-shared-ui/src/components/LoginViaSSOForm/LoginViaSSOForm.tsx index 3865ddbef..3027ad35c 100644 --- a/packages/javascript/bh-shared-ui/src/components/LoginViaSSOForm/LoginViaSSOForm.tsx +++ b/packages/javascript/bh-shared-ui/src/components/LoginViaSSOForm/LoginViaSSOForm.tsx @@ -21,23 +21,23 @@ import { SSOProvider } from 'js-client-library'; interface LoginViaSSOFormProps { providers: SSOProvider[] | undefined; - onSubmit: (redirectURL: string) => void; + onSubmit: (providerSlug: string) => void; onCancel: () => void; } const LoginViaSSOForm: React.FC = ({ providers, onSubmit, onCancel }) => { /* Hooks */ - const [redirectURL, setRedirectURL] = React.useState(''); + const [selectedProviderSlug, setSelectedProviderSlug] = React.useState(''); /* Event Handlers */ const handleSubmit: React.FormEventHandler = (e) => { e.preventDefault(); - if (redirectURL === null) { + if (selectedProviderSlug === null) { return; } - onSubmit(redirectURL); + onSubmit(selectedProviderSlug); }; /* Implementation */ @@ -50,12 +50,12 @@ const LoginViaSSOForm: React.FC = ({ providers, onSubmit,