@medplum/react 2.0.3 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/auth/AuthenticationForm.d.ts +2 -1
- package/dist/cjs/auth/SignInForm.d.ts +1 -0
- package/dist/cjs/index.cjs +40 -40
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.min.cjs +1 -1
- package/dist/esm/auth/AuthenticationForm.d.ts +2 -1
- package/dist/esm/auth/AuthenticationForm.mjs +1 -1
- package/dist/esm/auth/AuthenticationForm.mjs.map +1 -1
- package/dist/esm/auth/SignInForm.d.ts +1 -0
- package/dist/esm/auth/SignInForm.mjs +1 -1
- package/dist/esm/auth/SignInForm.mjs.map +1 -1
- package/dist/esm/index.min.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/createReactComponent.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/createReactComponent.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/defaultAttributes.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/defaultAttributes.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconAdjustmentsHorizontal.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconAdjustmentsHorizontal.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconAlertCircle.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconAlertCircle.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconBleach.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconBleach.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconBleachOff.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconBleachOff.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconBoxMultiple.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconBoxMultiple.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconBracketsContain.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconBracketsContain.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconBucket.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconBucket.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconBucketOff.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconBucketOff.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconCalendar.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconCalendar.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconCheck.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconCheck.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconCheckbox.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconCheckbox.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconCircleMinus.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconCircleMinus.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconCirclePlus.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconCirclePlus.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconCloudUpload.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconCloudUpload.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconColumns.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconColumns.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconCurrencyDollar.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconCurrencyDollar.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconDots.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconDots.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconEdit.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconEdit.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconEqual.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconEqual.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconEqualNot.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconEqualNot.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconFileAlert.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconFileAlert.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconFilePlus.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconFilePlus.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconFilter.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconFilter.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconListDetails.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconListDetails.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconMathGreater.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconMathGreater.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconMathLower.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconMathLower.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconMessage.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconMessage.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconPin.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconPin.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconPinnedOff.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconPinnedOff.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconSettings.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconSettings.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconSortAscending.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconSortAscending.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconSortDescending.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconSortDescending.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconSquare.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconSquare.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconTableExport.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconTableExport.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconTrash.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconTrash.mjs.map +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconX.mjs +1 -1
- package/dist/esm/node_modules/@tabler/icons-react/dist/esm/icons/IconX.mjs.map +1 -1
- package/package.json +12 -12
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BaseLoginRequest, LoginAuthenticationResponse } from '@medplum/core';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
export interface AuthenticationFormProps extends BaseLoginRequest {
|
|
4
|
+
readonly disableGoogleAuth?: boolean;
|
|
4
5
|
readonly onForgotPassword?: () => void;
|
|
5
6
|
readonly onRegister?: () => void;
|
|
6
7
|
readonly handleAuthResponse: (response: LoginAuthenticationResponse) => void;
|
|
@@ -8,7 +9,7 @@ export interface AuthenticationFormProps extends BaseLoginRequest {
|
|
|
8
9
|
}
|
|
9
10
|
export declare function AuthenticationForm(props: AuthenticationFormProps): JSX.Element;
|
|
10
11
|
export interface EmailFormProps extends BaseLoginRequest {
|
|
11
|
-
readonly
|
|
12
|
+
readonly disableGoogleAuth?: boolean;
|
|
12
13
|
readonly onRegister?: () => void;
|
|
13
14
|
readonly handleAuthResponse: (response: LoginAuthenticationResponse) => void;
|
|
14
15
|
readonly setEmail: (email: string) => void;
|
|
@@ -18,7 +18,7 @@ function AuthenticationForm(props) {
|
|
|
18
18
|
function EmailForm(props) {
|
|
19
19
|
const { setEmail, onRegister, handleAuthResponse, children, ...baseLoginRequest } = props;
|
|
20
20
|
const medplum = useMedplum();
|
|
21
|
-
const googleClientId = getGoogleClientId(props.googleClientId);
|
|
21
|
+
const googleClientId = !props.disableGoogleAuth && getGoogleClientId(props.googleClientId);
|
|
22
22
|
const isExternalAuth = useCallback(async (authMethod) => {
|
|
23
23
|
if (!authMethod.authorizeUrl) {
|
|
24
24
|
return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthenticationForm.mjs","sources":["../../../src/auth/AuthenticationForm.tsx"],"sourcesContent":["import { Anchor, Button, Center, Checkbox, Divider, Group, PasswordInput, Stack, TextInput } from '@mantine/core';\nimport {\n BaseLoginRequest,\n GoogleCredentialResponse,\n GoogleLoginRequest,\n LoginAuthenticationResponse,\n} from '@medplum/core';\nimport { OperationOutcome } from '@medplum/fhirtypes';\nimport React, { useCallback, useState } from 'react';\nimport { Form } from '../Form/Form';\nimport { getGoogleClientId, GoogleButton } from '../GoogleButton/GoogleButton';\nimport { useMedplum } from '../MedplumProvider/MedplumProvider';\nimport { OperationOutcomeAlert } from '../OperationOutcomeAlert/OperationOutcomeAlert';\nimport { getErrorsForInput, getIssuesForExpression } from '../utils/outcomes';\n\nexport interface AuthenticationFormProps extends BaseLoginRequest {\n readonly onForgotPassword?: () => void;\n readonly onRegister?: () => void;\n readonly handleAuthResponse: (response: LoginAuthenticationResponse) => void;\n readonly children?: React.ReactNode;\n}\n\nexport function AuthenticationForm(props: AuthenticationFormProps): JSX.Element {\n const [email, setEmail] = useState<string>();\n\n if (!email) {\n return <EmailForm setEmail={setEmail} {...props} />;\n } else {\n return <PasswordForm email={email} {...props} />;\n }\n}\n\nexport interface EmailFormProps extends BaseLoginRequest {\n readonly generatePkce?: boolean;\n readonly onRegister?: () => void;\n readonly handleAuthResponse: (response: LoginAuthenticationResponse) => void;\n readonly setEmail: (email: string) => void;\n readonly children?: React.ReactNode;\n}\n\nexport function EmailForm(props: EmailFormProps): JSX.Element {\n const { setEmail, onRegister, handleAuthResponse, children, ...baseLoginRequest } = props;\n const medplum = useMedplum();\n const googleClientId = getGoogleClientId(props.googleClientId);\n\n const isExternalAuth = useCallback(\n async (authMethod: any): Promise<boolean> => {\n if (!authMethod.authorizeUrl) {\n return false;\n }\n\n const state = JSON.stringify({\n ...(await medplum.ensureCodeChallenge(baseLoginRequest)),\n domain: authMethod.domain,\n });\n const url = new URL(authMethod.authorizeUrl);\n url.searchParams.set('state', state);\n window.location.assign(url.toString());\n return true;\n },\n [medplum, baseLoginRequest]\n );\n\n const handleSubmit = useCallback(\n async (formData: Record<string, string>) => {\n const authMethod = await medplum.post('auth/method', { email: formData.email });\n if (!(await isExternalAuth(authMethod))) {\n setEmail(formData.email);\n }\n },\n [medplum, isExternalAuth, setEmail]\n );\n\n const handleGoogleCredential = useCallback(\n async (response: GoogleCredentialResponse) => {\n const authResponse = await medplum.startGoogleLogin({\n ...baseLoginRequest,\n googleCredential: response.credential,\n } as GoogleLoginRequest);\n if (!(await isExternalAuth(authResponse))) {\n handleAuthResponse(authResponse);\n }\n },\n [medplum, baseLoginRequest, isExternalAuth, handleAuthResponse]\n );\n\n return (\n <Form style={{ maxWidth: 400 }} onSubmit={handleSubmit}>\n <Center sx={{ flexDirection: 'column' }}>{children}</Center>\n {googleClientId && (\n <>\n <Group position=\"center\" p=\"xl\" style={{ height: 70 }}>\n <GoogleButton googleClientId={googleClientId} handleGoogleCredential={handleGoogleCredential} />\n </Group>\n <Divider label=\"or\" labelPosition=\"center\" my=\"lg\" />\n </>\n )}\n <TextInput\n name=\"email\"\n type=\"email\"\n label=\"Email\"\n placeholder=\"name@domain.com\"\n required={true}\n autoFocus={true}\n />\n <Group position=\"apart\" mt=\"xl\" spacing={0} noWrap>\n {onRegister && (\n <Anchor component=\"button\" type=\"button\" color=\"dimmed\" onClick={onRegister} size=\"xs\">\n Register\n </Anchor>\n )}\n <Button type=\"submit\">Next</Button>\n </Group>\n </Form>\n );\n}\n\nexport interface PasswordFormProps extends BaseLoginRequest {\n readonly email: string;\n readonly onForgotPassword?: () => void;\n readonly handleAuthResponse: (response: LoginAuthenticationResponse) => void;\n readonly children?: React.ReactNode;\n}\n\nexport function PasswordForm(props: PasswordFormProps): JSX.Element {\n const { onForgotPassword, handleAuthResponse, children, ...baseLoginRequest } = props;\n const medplum = useMedplum();\n const [outcome, setOutcome] = useState<OperationOutcome>();\n const issues = getIssuesForExpression(outcome, undefined);\n\n const handleSubmit = useCallback(\n (formData: Record<string, string>) => {\n medplum\n .startLogin({\n ...baseLoginRequest,\n password: formData.password,\n remember: formData.remember === 'on',\n })\n .then(handleAuthResponse)\n .catch(setOutcome);\n },\n [medplum, baseLoginRequest, handleAuthResponse]\n );\n\n return (\n <Form style={{ maxWidth: 400 }} onSubmit={handleSubmit}>\n <Center sx={{ flexDirection: 'column' }}>{children}</Center>\n <OperationOutcomeAlert issues={issues} />\n <Stack spacing=\"xl\">\n <PasswordInput\n name=\"password\"\n label=\"Password\"\n autoComplete=\"off\"\n required={true}\n error={getErrorsForInput(outcome, 'password')}\n />\n </Stack>\n <Group position=\"apart\" mt=\"xl\" spacing={0} noWrap>\n {onForgotPassword && (\n <Anchor component=\"button\" type=\"button\" color=\"dimmed\" onClick={onForgotPassword} size=\"xs\">\n Forgot password\n </Anchor>\n )}\n <Checkbox id=\"remember\" name=\"remember\" label=\"Remember me\" size=\"xs\" sx={{ lineHeight: 1 }} />\n <Button type=\"submit\">Sign in</Button>\n </Group>\n </Form>\n );\n}\n"],"names":[],"mappings":";;;;;;;;AAsBM,SAAU,kBAAkB,CAAC,KAA8B,EAAA;IAC/D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAAU,CAAC;IAE7C,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,KAAA,CAAA,aAAA,CAAC,SAAS,EAAC,EAAA,QAAQ,EAAE,QAAQ,EAAA,GAAM,KAAK,EAAA,CAAI,CAAC;AACrD,KAAA;AAAM,SAAA;QACL,OAAO,KAAA,CAAA,aAAA,CAAC,YAAY,EAAC,EAAA,KAAK,EAAE,KAAK,EAAA,GAAM,KAAK,EAAA,CAAI,CAAC;AAClD,KAAA;AACH,CAAC;AAUK,SAAU,SAAS,CAAC,KAAqB,EAAA;AAC7C,IAAA,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,kBAAkB,EAAE,QAAQ,EAAE,GAAG,gBAAgB,EAAE,GAAG,KAAK,CAAC;AAC1F,IAAA,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7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,"file":"AuthenticationForm.mjs","sources":["../../../src/auth/AuthenticationForm.tsx"],"sourcesContent":["import { Anchor, Button, Center, Checkbox, Divider, Group, PasswordInput, Stack, TextInput } from '@mantine/core';\nimport {\n BaseLoginRequest,\n GoogleCredentialResponse,\n GoogleLoginRequest,\n LoginAuthenticationResponse,\n} from '@medplum/core';\nimport { OperationOutcome } from '@medplum/fhirtypes';\nimport React, { useCallback, useState } from 'react';\nimport { Form } from '../Form/Form';\nimport { getGoogleClientId, GoogleButton } from '../GoogleButton/GoogleButton';\nimport { useMedplum } from '../MedplumProvider/MedplumProvider';\nimport { OperationOutcomeAlert } from '../OperationOutcomeAlert/OperationOutcomeAlert';\nimport { getErrorsForInput, getIssuesForExpression } from '../utils/outcomes';\n\nexport interface AuthenticationFormProps extends BaseLoginRequest {\n readonly disableGoogleAuth?: boolean;\n readonly onForgotPassword?: () => void;\n readonly onRegister?: () => void;\n readonly handleAuthResponse: (response: LoginAuthenticationResponse) => void;\n readonly children?: React.ReactNode;\n}\n\nexport function AuthenticationForm(props: AuthenticationFormProps): JSX.Element {\n const [email, setEmail] = useState<string>();\n\n if (!email) {\n return <EmailForm setEmail={setEmail} {...props} />;\n } else {\n return <PasswordForm email={email} {...props} />;\n }\n}\n\nexport interface EmailFormProps extends BaseLoginRequest {\n readonly disableGoogleAuth?: boolean;\n readonly onRegister?: () => void;\n readonly handleAuthResponse: (response: LoginAuthenticationResponse) => void;\n readonly setEmail: (email: string) => void;\n readonly children?: React.ReactNode;\n}\n\nexport function EmailForm(props: EmailFormProps): JSX.Element {\n const { setEmail, onRegister, handleAuthResponse, children, ...baseLoginRequest } = props;\n const medplum = useMedplum();\n const googleClientId = !props.disableGoogleAuth && getGoogleClientId(props.googleClientId);\n\n const isExternalAuth = useCallback(\n async (authMethod: any): Promise<boolean> => {\n if (!authMethod.authorizeUrl) {\n return false;\n }\n\n const state = JSON.stringify({\n ...(await medplum.ensureCodeChallenge(baseLoginRequest)),\n domain: authMethod.domain,\n });\n const url = new URL(authMethod.authorizeUrl);\n url.searchParams.set('state', state);\n window.location.assign(url.toString());\n return true;\n },\n [medplum, baseLoginRequest]\n );\n\n const handleSubmit = useCallback(\n async (formData: Record<string, string>) => {\n const authMethod = await medplum.post('auth/method', { email: formData.email });\n if (!(await isExternalAuth(authMethod))) {\n setEmail(formData.email);\n }\n },\n [medplum, isExternalAuth, setEmail]\n );\n\n const handleGoogleCredential = useCallback(\n async (response: GoogleCredentialResponse) => {\n const authResponse = await medplum.startGoogleLogin({\n ...baseLoginRequest,\n googleCredential: response.credential,\n } as GoogleLoginRequest);\n if (!(await isExternalAuth(authResponse))) {\n handleAuthResponse(authResponse);\n }\n },\n [medplum, baseLoginRequest, isExternalAuth, handleAuthResponse]\n );\n\n return (\n <Form style={{ maxWidth: 400 }} onSubmit={handleSubmit}>\n <Center sx={{ flexDirection: 'column' }}>{children}</Center>\n {googleClientId && (\n <>\n <Group position=\"center\" p=\"xl\" style={{ height: 70 }}>\n <GoogleButton googleClientId={googleClientId} handleGoogleCredential={handleGoogleCredential} />\n </Group>\n <Divider label=\"or\" labelPosition=\"center\" my=\"lg\" />\n </>\n )}\n <TextInput\n name=\"email\"\n type=\"email\"\n label=\"Email\"\n placeholder=\"name@domain.com\"\n required={true}\n autoFocus={true}\n />\n <Group position=\"apart\" mt=\"xl\" spacing={0} noWrap>\n {onRegister && (\n <Anchor component=\"button\" type=\"button\" color=\"dimmed\" onClick={onRegister} size=\"xs\">\n Register\n </Anchor>\n )}\n <Button type=\"submit\">Next</Button>\n </Group>\n </Form>\n );\n}\n\nexport interface PasswordFormProps extends BaseLoginRequest {\n readonly email: string;\n readonly onForgotPassword?: () => void;\n readonly handleAuthResponse: (response: LoginAuthenticationResponse) => void;\n readonly children?: React.ReactNode;\n}\n\nexport function PasswordForm(props: PasswordFormProps): JSX.Element {\n const { onForgotPassword, handleAuthResponse, children, ...baseLoginRequest } = props;\n const medplum = useMedplum();\n const [outcome, setOutcome] = useState<OperationOutcome>();\n const issues = getIssuesForExpression(outcome, undefined);\n\n const handleSubmit = useCallback(\n (formData: Record<string, string>) => {\n medplum\n .startLogin({\n ...baseLoginRequest,\n password: formData.password,\n remember: formData.remember === 'on',\n })\n .then(handleAuthResponse)\n .catch(setOutcome);\n },\n [medplum, baseLoginRequest, handleAuthResponse]\n );\n\n return (\n <Form style={{ maxWidth: 400 }} onSubmit={handleSubmit}>\n <Center sx={{ flexDirection: 'column' }}>{children}</Center>\n <OperationOutcomeAlert issues={issues} />\n <Stack spacing=\"xl\">\n <PasswordInput\n name=\"password\"\n label=\"Password\"\n autoComplete=\"off\"\n required={true}\n error={getErrorsForInput(outcome, 'password')}\n />\n </Stack>\n <Group position=\"apart\" mt=\"xl\" spacing={0} noWrap>\n {onForgotPassword && (\n <Anchor component=\"button\" type=\"button\" color=\"dimmed\" onClick={onForgotPassword} size=\"xs\">\n Forgot password\n </Anchor>\n )}\n <Checkbox id=\"remember\" name=\"remember\" label=\"Remember me\" size=\"xs\" sx={{ lineHeight: 1 }} />\n <Button type=\"submit\">Sign in</Button>\n </Group>\n </Form>\n );\n}\n"],"names":[],"mappings":";;;;;;;;AAuBM,SAAU,kBAAkB,CAAC,KAA8B,EAAA;IAC/D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAAU,CAAC;IAE7C,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,KAAA,CAAA,aAAA,CAAC,SAAS,EAAC,EAAA,QAAQ,EAAE,QAAQ,EAAA,GAAM,KAAK,EAAA,CAAI,CAAC;AACrD,KAAA;AAAM,SAAA;QACL,OAAO,KAAA,CAAA,aAAA,CAAC,YAAY,EAAC,EAAA,KAAK,EAAE,KAAK,EAAA,GAAM,KAAK,EAAA,CAAI,CAAC;AAClD,KAAA;AACH,CAAC;AAUK,SAAU,SAAS,CAAC,KAAqB,EAAA;AAC7C,IAAA,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,kBAAkB,EAAE,QAAQ,EAAE,GAAG,gBA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CAAA,aAAA,CAAA,MAAM,IAAC,IAAI,EAAC,QAAQ,EAAiB,EAAA,SAAA,CAAA,CAChC,CACH,EACP;AACJ;;;;"}
|
|
@@ -3,6 +3,7 @@ import React from 'react';
|
|
|
3
3
|
export interface SignInFormProps extends BaseLoginRequest {
|
|
4
4
|
readonly login?: string;
|
|
5
5
|
readonly chooseScopes?: boolean;
|
|
6
|
+
readonly disableGoogleAuth?: boolean;
|
|
6
7
|
readonly onSuccess?: () => void;
|
|
7
8
|
readonly onForgotPassword?: () => void;
|
|
8
9
|
readonly onRegister?: () => void;
|
|
@@ -68,7 +68,7 @@ function SignInForm(props) {
|
|
|
68
68
|
}, [medplum, props, handleAuthResponse]);
|
|
69
69
|
return (React.createElement(Document, { width: 450 }, (() => {
|
|
70
70
|
if (!login) {
|
|
71
|
-
return (React.createElement(AuthenticationForm, { onForgotPassword: onForgotPassword, onRegister: onRegister, handleAuthResponse: handleAuthResponse, ...baseLoginRequest }, props.children));
|
|
71
|
+
return (React.createElement(AuthenticationForm, { onForgotPassword: onForgotPassword, onRegister: onRegister, handleAuthResponse: handleAuthResponse, disableGoogleAuth: props.disableGoogleAuth, ...baseLoginRequest }, props.children));
|
|
72
72
|
}
|
|
73
73
|
else if (mfaRequired) {
|
|
74
74
|
return React.createElement(MfaForm, { login: login, handleAuthResponse: handleAuthResponse });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SignInForm.mjs","sources":["../../../src/auth/SignInForm.tsx"],"sourcesContent":["import { BaseLoginRequest, LoginAuthenticationResponse } from '@medplum/core';\nimport { ProjectMembership } from '@medplum/fhirtypes';\nimport React, { useCallback, useEffect, useState } from 'react';\nimport { Document } from '../Document/Document';\nimport { useMedplum } from '../MedplumProvider/MedplumProvider';\nimport { AuthenticationForm } from './AuthenticationForm';\nimport { ChooseProfileForm } from './ChooseProfileForm';\nimport { ChooseScopeForm } from './ChooseScopeForm';\nimport { MfaForm } from './MfaForm';\nimport { NewProjectForm } from './NewProjectForm';\n\nexport interface SignInFormProps extends BaseLoginRequest {\n readonly login?: string;\n readonly chooseScopes?: boolean;\n readonly onSuccess?: () => void;\n readonly onForgotPassword?: () => void;\n readonly onRegister?: () => void;\n readonly onCode?: (code: string) => void;\n readonly children?: React.ReactNode;\n}\n\n/**\n * The SignInForm component allows users to sign in to Medplum.\n *\n * \"Signing in\" is a multi-step process:\n * 1) Authentication - identify the user\n * 2) MFA - If MFA is enabled, prompt for MFA code\n * 3) Choose profile - If the user has multiple profiles, prompt to choose one\n * 4) Choose scope - If the user has multiple scopes, prompt to choose one\n * 5) Success - Return to the caller with either a code or a redirect\n */\nexport function SignInForm(props: SignInFormProps): JSX.Element {\n const { chooseScopes, onSuccess, onForgotPassword, onRegister, onCode, ...baseLoginRequest } = props;\n const medplum = useMedplum();\n const [login, setLogin] = useState<string | undefined>(undefined);\n const [mfaRequired, setAuthenticatorRequired] = useState<boolean>(false);\n const [memberships, setMemberships] = useState<ProjectMembership[] | undefined>(undefined);\n\n const handleCode = useCallback(\n (code: string): void => {\n if (onCode) {\n onCode(code);\n } else {\n medplum\n .processCode(code)\n .then(() => {\n if (onSuccess) {\n onSuccess();\n }\n })\n .catch(console.log);\n }\n },\n [medplum, onCode, onSuccess]\n );\n\n const handleAuthResponse = useCallback(\n (response: LoginAuthenticationResponse): void => {\n setAuthenticatorRequired(!!response.mfaRequired);\n\n if (response.login) {\n setLogin(response.login);\n }\n\n if (response.memberships) {\n setMemberships(response.memberships);\n }\n\n if (response.code) {\n if (chooseScopes) {\n setMemberships(undefined);\n } else {\n handleCode(response.code as string);\n }\n }\n },\n [chooseScopes, handleCode]\n );\n\n const handleScopeResponse = useCallback(\n (response: LoginAuthenticationResponse): void => {\n handleCode(response.code as string);\n },\n [handleCode]\n );\n\n useEffect(() => {\n if (props.login) {\n medplum\n .get('auth/login/' + props.login)\n .then(handleAuthResponse)\n .catch(console.error);\n }\n }, [medplum, props, handleAuthResponse]);\n\n return (\n <Document width={450}>\n {(() => {\n if (!login) {\n return (\n <AuthenticationForm\n onForgotPassword={onForgotPassword}\n onRegister={onRegister}\n handleAuthResponse={handleAuthResponse}\n {...baseLoginRequest}\n >\n {props.children}\n </AuthenticationForm>\n );\n } else if (mfaRequired) {\n return <MfaForm login={login} handleAuthResponse={handleAuthResponse} />;\n } else if (memberships) {\n return <ChooseProfileForm login={login} memberships={memberships} handleAuthResponse={handleAuthResponse} />;\n } else if (props.projectId === 'new') {\n return <NewProjectForm login={login} handleAuthResponse={handleAuthResponse} />;\n } else if (props.chooseScopes) {\n return <ChooseScopeForm login={login} scope={props.scope} handleAuthResponse={handleScopeResponse} />;\n } else {\n return <div>Success</div>;\n }\n })()}\n </Document>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"SignInForm.mjs","sources":["../../../src/auth/SignInForm.tsx"],"sourcesContent":["import { BaseLoginRequest, LoginAuthenticationResponse } from '@medplum/core';\nimport { ProjectMembership } from '@medplum/fhirtypes';\nimport React, { useCallback, useEffect, useState } from 'react';\nimport { Document } from '../Document/Document';\nimport { useMedplum } from '../MedplumProvider/MedplumProvider';\nimport { AuthenticationForm } from './AuthenticationForm';\nimport { ChooseProfileForm } from './ChooseProfileForm';\nimport { ChooseScopeForm } from './ChooseScopeForm';\nimport { MfaForm } from './MfaForm';\nimport { NewProjectForm } from './NewProjectForm';\n\nexport interface SignInFormProps extends BaseLoginRequest {\n readonly login?: string;\n readonly chooseScopes?: boolean;\n readonly disableGoogleAuth?: boolean;\n readonly onSuccess?: () => void;\n readonly onForgotPassword?: () => void;\n readonly onRegister?: () => void;\n readonly onCode?: (code: string) => void;\n readonly children?: React.ReactNode;\n}\n\n/**\n * The SignInForm component allows users to sign in to Medplum.\n *\n * \"Signing in\" is a multi-step process:\n * 1) Authentication - identify the user\n * 2) MFA - If MFA is enabled, prompt for MFA code\n * 3) Choose profile - If the user has multiple profiles, prompt to choose one\n * 4) Choose scope - If the user has multiple scopes, prompt to choose one\n * 5) Success - Return to the caller with either a code or a redirect\n */\nexport function SignInForm(props: SignInFormProps): JSX.Element {\n const { chooseScopes, onSuccess, onForgotPassword, onRegister, onCode, ...baseLoginRequest } = props;\n const medplum = useMedplum();\n const [login, setLogin] = useState<string | undefined>(undefined);\n const [mfaRequired, setAuthenticatorRequired] = useState<boolean>(false);\n const [memberships, setMemberships] = useState<ProjectMembership[] | undefined>(undefined);\n\n const handleCode = useCallback(\n (code: string): void => {\n if (onCode) {\n onCode(code);\n } else {\n medplum\n .processCode(code)\n .then(() => {\n if (onSuccess) {\n onSuccess();\n }\n })\n .catch(console.log);\n }\n },\n [medplum, onCode, onSuccess]\n );\n\n const handleAuthResponse = useCallback(\n (response: LoginAuthenticationResponse): void => {\n setAuthenticatorRequired(!!response.mfaRequired);\n\n if (response.login) {\n setLogin(response.login);\n }\n\n if (response.memberships) {\n setMemberships(response.memberships);\n }\n\n if (response.code) {\n if (chooseScopes) {\n setMemberships(undefined);\n } else {\n handleCode(response.code as string);\n }\n }\n },\n [chooseScopes, handleCode]\n );\n\n const handleScopeResponse = useCallback(\n (response: LoginAuthenticationResponse): void => {\n handleCode(response.code as string);\n },\n [handleCode]\n );\n\n useEffect(() => {\n if (props.login) {\n medplum\n .get('auth/login/' + props.login)\n .then(handleAuthResponse)\n .catch(console.error);\n }\n }, [medplum, props, handleAuthResponse]);\n\n return (\n <Document width={450}>\n {(() => {\n if (!login) {\n return (\n <AuthenticationForm\n onForgotPassword={onForgotPassword}\n onRegister={onRegister}\n handleAuthResponse={handleAuthResponse}\n disableGoogleAuth={props.disableGoogleAuth}\n {...baseLoginRequest}\n >\n {props.children}\n </AuthenticationForm>\n );\n } else if (mfaRequired) {\n return <MfaForm login={login} handleAuthResponse={handleAuthResponse} />;\n } else if (memberships) {\n return <ChooseProfileForm login={login} memberships={memberships} handleAuthResponse={handleAuthResponse} />;\n } else if (props.projectId === 'new') {\n return <NewProjectForm login={login} handleAuthResponse={handleAuthResponse} />;\n } else if (props.chooseScopes) {\n return <ChooseScopeForm login={login} scope={props.scope} handleAuthResponse={handleScopeResponse} />;\n } else {\n return <div>Success</div>;\n }\n })()}\n </Document>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;AAsBA;;;;;;;;;AASG;AACG,SAAU,UAAU,CAAC,KAAsB,EAAA;AAC/C,IAAA,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,gBAAgB,EAAE,GAAG,KAAK,CAAC;AACrG,IAAA,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAqB,SAAS,CAAC,CAAC;IAClE,MAAM,CAAC,WAAW,EAAE,wBAAwB,CAAC,GAAG,QAAQ,CAAU,KAAK,CAAC,CAAC;IACzE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAkC,SAAS,CAAC,CAAC;AAE3F,IAAA,MAAM,UAAU,GAAG,WAAW,CAC5B,CAAC,IAAY,KAAU;AACrB,QAAA,IAAI,MAAM,EAAE;YACV,MAAM,CAAC,IAAI,CAAC,CAAC;AACd,SAAA;AAAM,aAAA;YACL,OAAO;iBACJ,WAAW,CAAC,IAAI,CAAC;iBACjB,IAAI,CAAC,MAAK;AACT,gBAAA,IAAI,SAAS,EAAE;AACb,oBAAA,SAAS,EAAE,CAAC;AACb,iBAAA;AACH,aAAC,CAAC;AACD,iBAAA,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AACvB,SAAA;KACF,EACD,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,CAC7B,CAAC;AAEF,IAAA,MAAM,kBAAkB,GAAG,WAAW,CACpC,CAAC,QAAqC,KAAU;AAC9C,QAAA,wBAAwB,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QAEjD,IAAI,QAAQ,CAAC,KAAK,EAAE;AAClB,YAAA,QAAQ,CAAC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