Skip to content

Commit

Permalink
Handle correctly different auth methods in the modal
Browse files Browse the repository at this point in the history
  • Loading branch information
MytsV authored and maany committed Aug 8, 2024
1 parent c5b3056 commit 17d36b0
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/component-library/Pages/Login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ export interface LoginPageProps {


interface MultipleAccountsModal {
submitX509: (account: string | undefined) => Promise<void>,
submit: (account: string | undefined) => Promise<void>,
availableAccounts: string[],
onClose: () => void,
}


const MultipleAccountsModal = ({
submitX509,
submit,
availableAccounts,
onClose
}: MultipleAccountsModal) => {
Expand Down Expand Up @@ -74,7 +74,7 @@ const MultipleAccountsModal = ({
label="Select"
disabled={chosenAccount === undefined}
onClick={async () => {
await submitX509(chosenAccount);
await submit(chosenAccount);
}}
/>
</Modal>
Expand All @@ -101,6 +101,7 @@ export const Login = ({
const [error, setError] = useState<string | undefined>(undefined)

const [availableAccounts, setAvailableAccounts] = useState<string[]>([])
const [lastAuthMethod, setLastAuthMethod] = useState<'userpass' | 'x509' | undefined>(undefined)

const handleAuthViewModel = (authViewModel: AuthViewModel) => {
if (authViewModel.status === 'error') {
Expand All @@ -117,10 +118,17 @@ export const Login = ({

if (!x509AuthViewModel) return

setLastAuthMethod('x509')
handleAuthViewModel(x509AuthViewModel)
handleX509Session(x509AuthViewModel, account || "", vo.shortName)
};

const submitUserPass = async (account: string | undefined) => {
handleUserPassSubmit(username, password, loginViewModel.voList[selectedVOTab], account)
setLastAuthMethod('userpass')
return Promise.resolve()
}

useEffect(() => {
if (authViewModel) {
handleAuthViewModel(authViewModel)
Expand All @@ -140,7 +148,7 @@ export const Login = ({
id="root"
>
<MultipleAccountsModal
submitX509={submitX509}
submit={lastAuthMethod === 'x509' ? submitX509 : submitUserPass}
availableAccounts={availableAccounts}
onClose={() => setAvailableAccounts([])}
/>
Expand Down Expand Up @@ -228,14 +236,7 @@ export const Login = ({
label="Login"
type="submit"
role="button"
onClick={async () => {
await handleUserPassSubmit(
username,
password,
loginViewModel.voList[selectedVOTab],
inputAccount
)
}}
onClick={() => submitUserPass(inputAccount)}
/>
</fieldset>
</form>
Expand Down

0 comments on commit 17d36b0

Please sign in to comment.