@medplum/react 1.0.6 → 2.0.0

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.
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { OperationOutcomeIssue } from '@medplum/fhirtypes';
3
+ export interface OperationOutcomeAlertProps {
4
+ issues?: OperationOutcomeIssue[];
5
+ }
6
+ export declare function OperationOutcomeAlert(props: OperationOutcomeAlertProps): JSX.Element | null;
@@ -0,0 +1,13 @@
1
+ import { Alert } from '@mantine/core';
2
+ import { IconAlertCircle } from '@tabler/icons';
3
+ import React from 'react';
4
+
5
+ function OperationOutcomeAlert(props) {
6
+ if (!props.issues) {
7
+ return null;
8
+ }
9
+ return (React.createElement(Alert, { icon: React.createElement(IconAlertCircle, { size: 16 }), color: "red" }, props.issues.map((issue) => (React.createElement("div", { "data-testid": "text-field-error", key: issue.details?.text }, issue.details?.text)))));
10
+ }
11
+
12
+ export { OperationOutcomeAlert };
13
+ //# sourceMappingURL=OperationOutcomeAlert.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OperationOutcomeAlert.mjs","sources":["../../../src/OperationOutcomeAlert/OperationOutcomeAlert.tsx"],"sourcesContent":["import { Alert } from '@mantine/core';\nimport { OperationOutcomeIssue } from '@medplum/fhirtypes';\nimport { IconAlertCircle } from '@tabler/icons';\nimport React from 'react';\n\nexport interface OperationOutcomeAlertProps {\n issues?: OperationOutcomeIssue[];\n}\n\nexport function OperationOutcomeAlert(props: OperationOutcomeAlertProps): JSX.Element | null {\n if (!props.issues) {\n return null;\n }\n return (\n <Alert icon={<IconAlertCircle size={16} />} color=\"red\">\n {props.issues.map((issue) => (\n <div data-testid=\"text-field-error\" key={issue.details?.text}>\n {issue.details?.text}\n </div>\n ))}\n </Alert>\n );\n}\n"],"names":[],"mappings":";;;;AASM,SAAU,qBAAqB,CAAC,KAAiC,EAAA;AACrE,IAAA,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE;AACjB,QAAA,OAAO,IAAI,CAAC;AACb,KAAA;IACD,QACE,oBAAC,KAAK,EAAA,EAAC,IAAI,EAAE,KAAA,CAAA,aAAA,CAAC,eAAe,EAAA,EAAC,IAAI,EAAE,EAAE,EAAI,CAAA,EAAE,KAAK,EAAC,KAAK,EAAA,EACpD,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,MACtB,KAAiB,CAAA,aAAA,CAAA,KAAA,EAAA,EAAA,aAAA,EAAA,kBAAkB,EAAC,GAAG,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI,EACzD,EAAA,KAAK,CAAC,OAAO,EAAE,IAAI,CAChB,CACP,CAAC,CACI,EACR;AACJ;;;;"}
@@ -1,10 +1,24 @@
1
1
  import { BaseLoginRequest, LoginAuthenticationResponse } from '@medplum/core';
2
2
  import React from 'react';
3
3
  export interface AuthenticationFormProps extends BaseLoginRequest {
4
- readonly generatePkce?: boolean;
5
4
  readonly onForgotPassword?: () => void;
6
5
  readonly onRegister?: () => void;
7
6
  readonly handleAuthResponse: (response: LoginAuthenticationResponse) => void;
8
7
  readonly children?: React.ReactNode;
9
8
  }
10
9
  export declare function AuthenticationForm(props: AuthenticationFormProps): JSX.Element;
10
+ export interface EmailFormProps extends BaseLoginRequest {
11
+ readonly generatePkce?: boolean;
12
+ readonly onRegister?: () => void;
13
+ readonly handleAuthResponse: (response: LoginAuthenticationResponse) => void;
14
+ readonly setEmail: (email: string) => void;
15
+ readonly children?: React.ReactNode;
16
+ }
17
+ export declare function EmailForm(props: EmailFormProps): JSX.Element;
18
+ export interface PasswordFormProps extends BaseLoginRequest {
19
+ readonly email: string;
20
+ readonly onForgotPassword?: () => void;
21
+ readonly handleAuthResponse: (response: LoginAuthenticationResponse) => void;
22
+ readonly children?: React.ReactNode;
23
+ }
24
+ export declare function PasswordForm(props: PasswordFormProps): JSX.Element;
@@ -1,56 +1,88 @@
1
- import { Center, Alert, Group, Divider, Stack, TextInput, PasswordInput, Anchor, Checkbox, Button } from '@mantine/core';
2
- import { IconAlertCircle } from '@tabler/icons';
3
- import React, { useState } from 'react';
1
+ import { Center, Group, Divider, TextInput, Anchor, Button, Stack, PasswordInput, Checkbox } from '@mantine/core';
2
+ import React, { useState, useCallback } from 'react';
4
3
  import { Form } from '../Form/Form.mjs';
5
4
  import { getGoogleClientId, GoogleButton } from '../GoogleButton/GoogleButton.mjs';
6
5
  import { useMedplum } from '../MedplumProvider/MedplumProvider.mjs';
6
+ import { OperationOutcomeAlert } from '../OperationOutcomeAlert/OperationOutcomeAlert.mjs';
7
7
  import { getIssuesForExpression, getErrorsForInput } from '../utils/outcomes.mjs';
8
8
 
9
9
  function AuthenticationForm(props) {
10
- const { generatePkce, onForgotPassword, onRegister, handleAuthResponse, children, ...baseLoginRequest } = props;
10
+ const [email, setEmail] = useState();
11
+ if (!email) {
12
+ return React.createElement(EmailForm, { setEmail: setEmail, ...props });
13
+ }
14
+ else {
15
+ return React.createElement(PasswordForm, { email: email, ...props });
16
+ }
17
+ }
18
+ function EmailForm(props) {
19
+ const { setEmail, onRegister, handleAuthResponse, children, ...baseLoginRequest } = props;
11
20
  const medplum = useMedplum();
12
21
  const googleClientId = getGoogleClientId(props.googleClientId);
13
- const [outcome, setOutcome] = useState();
14
- const issues = getIssuesForExpression(outcome, undefined);
15
- async function startPkce() {
16
- if (generatePkce) {
17
- await medplum.startPkce();
22
+ const isExternalAuth = useCallback(async (authMethod) => {
23
+ if (!authMethod.authorizeUrl) {
24
+ return false;
18
25
  }
19
- }
20
- return (React.createElement(Form, { style: { maxWidth: 400 }, onSubmit: (formData) => {
21
- startPkce()
22
- .then(() => medplum.startLogin({
23
- ...baseLoginRequest,
24
- email: formData.email,
25
- password: formData.password,
26
- remember: formData.remember === 'on',
27
- }))
28
- .then(handleAuthResponse)
29
- .catch(setOutcome);
30
- } },
26
+ const state = JSON.stringify({
27
+ ...(await medplum.ensureCodeChallenge(baseLoginRequest)),
28
+ domain: authMethod.domain,
29
+ });
30
+ const url = new URL(authMethod.authorizeUrl);
31
+ url.searchParams.set('state', state);
32
+ window.location.assign(url.toString());
33
+ return true;
34
+ }, [medplum, baseLoginRequest]);
35
+ const handleSubmit = useCallback(async (formData) => {
36
+ const authMethod = await medplum.post('auth/method', { email: formData.email });
37
+ if (!(await isExternalAuth(authMethod))) {
38
+ setEmail(formData.email);
39
+ }
40
+ }, [medplum, isExternalAuth, setEmail]);
41
+ const handleGoogleCredential = useCallback(async (response) => {
42
+ const authResponse = await medplum.startGoogleLogin({
43
+ ...baseLoginRequest,
44
+ googleCredential: response.credential,
45
+ });
46
+ if (!(await isExternalAuth(authResponse))) {
47
+ handleAuthResponse(authResponse);
48
+ }
49
+ }, [medplum, baseLoginRequest, isExternalAuth, handleAuthResponse]);
50
+ return (React.createElement(Form, { style: { maxWidth: 400 }, onSubmit: handleSubmit },
31
51
  React.createElement(Center, { sx: { flexDirection: 'column' } }, children),
32
- issues && (React.createElement(Alert, { icon: React.createElement(IconAlertCircle, { size: 16 }), color: "red" }, issues.map((issue) => (React.createElement("div", { "data-testid": "text-field-error", key: issue.details?.text }, issue.details?.text))))),
33
52
  googleClientId && (React.createElement(React.Fragment, null,
34
53
  React.createElement(Group, { position: "center", p: "xl", style: { height: 70 } },
35
- React.createElement(GoogleButton, { googleClientId: googleClientId, handleGoogleCredential: (response) => {
36
- startPkce()
37
- .then(() => medplum.startGoogleLogin({
38
- ...baseLoginRequest,
39
- googleCredential: response.credential,
40
- }))
41
- .then(props.handleAuthResponse)
42
- .catch(setOutcome);
43
- } })),
54
+ React.createElement(GoogleButton, { googleClientId: googleClientId, handleGoogleCredential: handleGoogleCredential })),
44
55
  React.createElement(Divider, { label: "or", labelPosition: "center", my: "lg" }))),
56
+ React.createElement(TextInput, { name: "email", type: "email", label: "Email", placeholder: "name@domain.com", required: true, autoFocus: true }),
57
+ React.createElement(Group, { position: "apart", mt: "xl", spacing: 0, noWrap: true },
58
+ onRegister && (React.createElement(Anchor, { component: "button", type: "button", color: "dimmed", onClick: onRegister, size: "xs" }, "Register")),
59
+ React.createElement(Button, { type: "submit" }, "Next"))));
60
+ }
61
+ function PasswordForm(props) {
62
+ const { onForgotPassword, handleAuthResponse, children, ...baseLoginRequest } = props;
63
+ const medplum = useMedplum();
64
+ const [outcome, setOutcome] = useState();
65
+ const issues = getIssuesForExpression(outcome, undefined);
66
+ const handleSubmit = useCallback((formData) => {
67
+ medplum
68
+ .startLogin({
69
+ ...baseLoginRequest,
70
+ password: formData.password,
71
+ remember: formData.remember === 'on',
72
+ })
73
+ .then(handleAuthResponse)
74
+ .catch(setOutcome);
75
+ }, [medplum, baseLoginRequest, handleAuthResponse]);
76
+ return (React.createElement(Form, { style: { maxWidth: 400 }, onSubmit: handleSubmit },
77
+ React.createElement(Center, { sx: { flexDirection: 'column' } }, children),
78
+ React.createElement(OperationOutcomeAlert, { issues: issues }),
45
79
  React.createElement(Stack, { spacing: "xl" },
46
- React.createElement(TextInput, { name: "email", type: "email", label: "Email", placeholder: "name@domain.com", required: true, autoFocus: true, error: getErrorsForInput(outcome, 'email') }),
47
80
  React.createElement(PasswordInput, { name: "password", type: "password", label: "Password", autoComplete: "off", required: true, error: getErrorsForInput(outcome, 'password') })),
48
81
  React.createElement(Group, { position: "apart", mt: "xl", spacing: 0, noWrap: true },
49
82
  onForgotPassword && (React.createElement(Anchor, { component: "button", type: "button", color: "dimmed", onClick: onForgotPassword, size: "xs" }, "Forgot password")),
50
- onRegister && (React.createElement(Anchor, { component: "button", type: "button", color: "dimmed", onClick: onRegister, size: "xs" }, "Register")),
51
83
  React.createElement(Checkbox, { id: "remember", name: "remember", label: "Remember me", size: "xs", sx: { lineHeight: 1 } }),
52
84
  React.createElement(Button, { type: "submit" }, "Sign in"))));
53
85
  }
54
86
 
55
- export { AuthenticationForm };
87
+ export { AuthenticationForm, EmailForm, PasswordForm };
56
88
  //# sourceMappingURL=AuthenticationForm.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"AuthenticationForm.mjs","sources":["../../../src/auth/AuthenticationForm.tsx"],"sourcesContent":["import {\n Alert,\n Anchor,\n Button,\n Center,\n Checkbox,\n Divider,\n Group,\n PasswordInput,\n Stack,\n TextInput,\n} from '@mantine/core';\nimport {\n BaseLoginRequest,\n GoogleCredentialResponse,\n GoogleLoginRequest,\n LoginAuthenticationResponse,\n} from '@medplum/core';\nimport { OperationOutcome } from '@medplum/fhirtypes';\nimport { IconAlertCircle } from '@tabler/icons';\nimport React, { useState } from 'react';\nimport { Form } from '../Form/Form';\nimport { getGoogleClientId, GoogleButton } from '../GoogleButton/GoogleButton';\nimport { useMedplum } from '../MedplumProvider/MedplumProvider';\nimport { getErrorsForInput, getIssuesForExpression } from '../utils/outcomes';\n\nexport interface AuthenticationFormProps extends BaseLoginRequest {\n readonly generatePkce?: 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 { generatePkce, onForgotPassword, onRegister, handleAuthResponse, children, ...baseLoginRequest } = props;\n const medplum = useMedplum();\n const googleClientId = getGoogleClientId(props.googleClientId);\n const [outcome, setOutcome] = useState<OperationOutcome>();\n const issues = getIssuesForExpression(outcome, undefined);\n\n async function startPkce(): Promise<void> {\n if (generatePkce) {\n await medplum.startPkce();\n }\n }\n\n return (\n <Form\n style={{ maxWidth: 400 }}\n onSubmit={(formData: Record<string, string>) => {\n startPkce()\n .then(() =>\n medplum.startLogin({\n ...baseLoginRequest,\n email: formData.email,\n password: formData.password,\n remember: formData.remember === 'on',\n })\n )\n .then(handleAuthResponse)\n .catch(setOutcome);\n }}\n >\n <Center sx={{ flexDirection: 'column' }}>{children}</Center>\n {issues && (\n <Alert icon={<IconAlertCircle size={16} />} color=\"red\">\n {issues.map((issue) => (\n <div data-testid=\"text-field-error\" key={issue.details?.text}>\n {issue.details?.text}\n </div>\n ))}\n </Alert>\n )}\n {googleClientId && (\n <>\n <Group position=\"center\" p=\"xl\" style={{ height: 70 }}>\n <GoogleButton\n googleClientId={googleClientId}\n handleGoogleCredential={(response: GoogleCredentialResponse) => {\n startPkce()\n .then(() =>\n medplum.startGoogleLogin({\n ...baseLoginRequest,\n googleCredential: response.credential,\n } as GoogleLoginRequest)\n )\n .then(props.handleAuthResponse)\n .catch(setOutcome);\n }}\n />\n </Group>\n <Divider label=\"or\" labelPosition=\"center\" my=\"lg\" />\n </>\n )}\n <Stack spacing=\"xl\">\n <TextInput\n name=\"email\"\n type=\"email\"\n label=\"Email\"\n placeholder=\"name@domain.com\"\n required={true}\n autoFocus={true}\n error={getErrorsForInput(outcome, 'email')}\n />\n <PasswordInput\n name=\"password\"\n type=\"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 {onRegister && (\n <Anchor component=\"button\" type=\"button\" color=\"dimmed\" onClick={onRegister} size=\"xs\">\n Register\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":";;;;;;;;AAkCM,SAAU,kBAAkB,CAAC,KAA8B,EAAA;AAC/D,IAAA,MAAM,EAAE,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,kBAAkB,EAAE,QAAQ,EAAE,GAAG,gBAAgB,EAAE,GAAG,KAAK,CAAC;AAChH,IAAA,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,cAAc,GAAG,iBAAiB,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAC/D,MAAM,CAAC,OAAO,EAAE,UAA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YAAY,EAAC,KAAK,EAClB,QAAQ,EAAE,IAAI,EACd,KAAK,EAAE,iBAAiB,CAAC,OAAO,EAAE,UAAU,CAAC,GAC7C,CACI;AACR,QAAA,KAAA,CAAA,aAAA,CAAC,KAAK,EAAA,EAAC,QAAQ,EAAC,OAAO,EAAC,EAAE,EAAC,IAAI,EAAC,OAAO,EAAE,CAAC,EAAE,MAAM,EAAA,IAAA,EAAA;YAC/C,gBAAgB,KACf,KAAA,CAAA,aAAA,CAAC,MAAM,EAAA,EAAC,SAAS,EAAC,QAAQ,EAAC,IAAI,EAAC,QAAQ,EAAC,KAAK,EAAC,QAAQ,EAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAC,IAAI,EAAA,EAAA,iBAAA,CAEnF,CACV;YACA,UAAU,KACT,KAAA,CAAA,aAAA,CAAC,MAAM,EAAA,EAAC,SAAS,EAAC,QAAQ,EAAC,IAAI,EAAC,QAAQ,EAAC,KAAK,EAAC,QAAQ,EAAC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAC,IAAI,EAAA,EAAA,UAAA,CAE7E,CACV;YACD,KAAC,CAAA,aAAA,CAAA,QAAQ,EAAC,EAAA,EAAE,EAAC,UAAU,EAAC,IAAI,EAAC,UAAU,EAAC,KAAK,EAAC,aAAa,EAAC,IAAI,EAAC,IAAI,EAAC,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,EAAI,CAAA;YAC/F,KAAC,CAAA,aAAA,CAAA,MAAM,IAAC,IAAI,EAAC,QAAQ,EAAiB,EAAA,SAAA,CAAA,CAChC,CACH,EACP;AACJ;;;;"}
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 type=\"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;IAC7B,MAAM,cAAc,GAAG,iBAAiB,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAE/D,MAAM,cAAc,GAAG,WAAW,CAChC,OAAO,UAAe,KAAsB;AAC1C,QAAA,IAAI,CAAC,UAAU,CAAC,YAAY,EAAE;AAC5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CAAA,aAAA,CAAC,qBAAqB,EAAA,EAAC,MAAM,EAAE,MAAM,EAAI,CAAA;AACzC,QAAA,KAAA,CAAA,aAAA,CAAC,KAAK,EAAA,EAAC,OAAO,EAAC,IAAI,EAAA;AACjB,YAAA,KAAA,CAAA,aAAA,CAAC,aAAa,EAAA,EACZ,IAAI,EAAC,UAAU,EACf,IAAI,EAAC,UAAU,EACf,KAAK,EAAC,UAAU,EAChB,YAAY,EAAC,KAAK,EAClB,QAAQ,EAAE,IAAI,EACd,KAAK,EAAE,iBAAiB,CAAC,OAAO,EAAE,UAAU,CAAC,GAC7C,CACI;AACR,QAAA,KAAA,CAAA,aAAA,CAAC,KAAK,EAAA,EAAC,QAAQ,EAAC,OAAO,EAAC,EAAE,EAAC,IAAI,EAAC,OAAO,EAAE,CAAC,EAAE,MAAM,EAAA,IAAA,EAAA;YAC/C,gBAAgB,KACf,KAAA,CAAA,aAAA,CAAC,MAAM,EAAA,EAAC,SAAS,EAAC,QAAQ,EAAC,IAAI,EAAC,QAAQ,EAAC,KAAK,EAAC,QAAQ,EAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAC,IAAI,EAAA,EAAA,iBAAA,CAEnF,CACV;YACD,KAAC,CAAA,aAAA,CAAA,QAAQ,EAAC,EAAA,EAAE,EAAC,UAAU,EAAC,IAAI,EAAC,UAAU,EAAC,KAAK,EAAC,aAAa,EAAC,IAAI,EAAC,IAAI,EAAC,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,EAAI,CAAA;YAC/F,KAAC,CAAA,aAAA,CAAA,MAAM,IAAC,IAAI,EAAC,QAAQ,EAAiB,EAAA,SAAA,CAAA,CAChC,CACH,EACP;AACJ;;;;"}
@@ -1,9 +1,9 @@
1
- import { Center, Alert, Group, Divider, Stack, TextInput, PasswordInput, Text, Anchor, Checkbox, Button } from '@mantine/core';
2
- import { IconAlertCircle } from '@tabler/icons';
1
+ import { Center, Group, Divider, Stack, TextInput, PasswordInput, Text, Anchor, Checkbox, Button } from '@mantine/core';
3
2
  import React, { useState, useEffect } from 'react';
4
3
  import { Form } from '../Form/Form.mjs';
5
4
  import { getGoogleClientId, GoogleButton } from '../GoogleButton/GoogleButton.mjs';
6
5
  import { useMedplum } from '../MedplumProvider/MedplumProvider.mjs';
6
+ import { OperationOutcomeAlert } from '../OperationOutcomeAlert/OperationOutcomeAlert.mjs';
7
7
  import { getIssuesForExpression, getErrorsForInput } from '../utils/outcomes.mjs';
8
8
  import { initRecaptcha, getRecaptcha } from '../utils/recaptcha.mjs';
9
9
 
@@ -33,12 +33,11 @@ function NewUserForm(props) {
33
33
  }
34
34
  } },
35
35
  React.createElement(Center, { sx: { flexDirection: 'column' } }, props.children),
36
- issues && (React.createElement(Alert, { icon: React.createElement(IconAlertCircle, { size: 16 }), color: "red" }, issues.map((issue) => (React.createElement("div", { "data-testid": "text-field-error", key: issue.details?.text }, issue.details?.text))))),
36
+ React.createElement(OperationOutcomeAlert, { issues: issues }),
37
37
  googleClientId && (React.createElement(React.Fragment, null,
38
38
  React.createElement(Group, { position: "center", p: "xl", style: { height: 70 } },
39
39
  React.createElement(GoogleButton, { googleClientId: googleClientId, handleGoogleCredential: async (response) => {
40
40
  try {
41
- await medplum.startPkce();
42
41
  props.handleAuthResponse(await medplum.startGoogleLogin({
43
42
  googleClientId: response.clientId,
44
43
  googleCredential: response.credential,
@@ -1 +1 @@
1
- {"version":3,"file":"NewUserForm.mjs","sources":["../../../src/auth/NewUserForm.tsx"],"sourcesContent":["import {\n Alert,\n Anchor,\n Button,\n Center,\n Checkbox,\n Divider,\n Group,\n PasswordInput,\n Stack,\n Text,\n TextInput,\n} from '@mantine/core';\nimport { GoogleCredentialResponse, LoginAuthenticationResponse } from '@medplum/core';\nimport { OperationOutcome } from '@medplum/fhirtypes';\nimport { IconAlertCircle } from '@tabler/icons';\nimport React, { useEffect, useState } from 'react';\nimport { Form } from '../Form/Form';\nimport { getGoogleClientId, GoogleButton } from '../GoogleButton/GoogleButton';\nimport { useMedplum } from '../MedplumProvider/MedplumProvider';\nimport { getErrorsForInput, getIssuesForExpression } from '../utils/outcomes';\nimport { getRecaptcha, initRecaptcha } from '../utils/recaptcha';\n\nexport interface NewUserFormProps {\n readonly projectId: string;\n readonly googleClientId?: string;\n readonly recaptchaSiteKey: string;\n readonly children?: React.ReactNode;\n readonly handleAuthResponse: (response: LoginAuthenticationResponse) => void;\n}\n\nexport function NewUserForm(props: NewUserFormProps): JSX.Element {\n const googleClientId = getGoogleClientId(props.googleClientId);\n const recaptchaSiteKey = props.recaptchaSiteKey;\n const medplum = useMedplum();\n const [outcome, setOutcome] = useState<OperationOutcome>();\n const issues = getIssuesForExpression(outcome, undefined);\n\n useEffect(() => initRecaptcha(recaptchaSiteKey), [recaptchaSiteKey]);\n\n return (\n <Form\n style={{ maxWidth: 400 }}\n onSubmit={async (formData: Record<string, string>) => {\n try {\n const recaptchaToken = await getRecaptcha(recaptchaSiteKey);\n props.handleAuthResponse(\n await medplum.startNewUser({\n projectId: props.projectId,\n firstName: formData.firstName,\n lastName: formData.lastName,\n email: formData.email,\n password: formData.password,\n remember: formData.remember === 'true',\n recaptchaSiteKey,\n recaptchaToken,\n })\n );\n } catch (err) {\n setOutcome(err as OperationOutcome);\n }\n }}\n >\n <Center sx={{ flexDirection: 'column' }}>{props.children}</Center>\n {issues && (\n <Alert icon={<IconAlertCircle size={16} />} color=\"red\">\n {issues.map((issue) => (\n <div data-testid=\"text-field-error\" key={issue.details?.text}>\n {issue.details?.text}\n </div>\n ))}\n </Alert>\n )}\n {googleClientId && (\n <>\n <Group position=\"center\" p=\"xl\" style={{ height: 70 }}>\n <GoogleButton\n googleClientId={googleClientId}\n handleGoogleCredential={async (response: GoogleCredentialResponse) => {\n try {\n await medplum.startPkce();\n props.handleAuthResponse(\n await medplum.startGoogleLogin({\n googleClientId: response.clientId,\n googleCredential: response.credential,\n createUser: true,\n })\n );\n } catch (err) {\n setOutcome(err as OperationOutcome);\n }\n }}\n />\n </Group>\n <Divider label=\"or\" labelPosition=\"center\" my=\"lg\" />\n </>\n )}\n <Stack spacing=\"xl\">\n <TextInput\n name=\"firstName\"\n type=\"text\"\n label=\"First name\"\n placeholder=\"First name\"\n required={true}\n autoFocus={true}\n error={getErrorsForInput(outcome, 'firstName')}\n />\n <TextInput\n name=\"lastName\"\n type=\"text\"\n label=\"Last name\"\n placeholder=\"Last name\"\n required={true}\n error={getErrorsForInput(outcome, 'lastName')}\n />\n <TextInput\n name=\"email\"\n type=\"email\"\n label=\"Email\"\n placeholder=\"name@domain.com\"\n required={true}\n error={getErrorsForInput(outcome, 'email')}\n />\n <PasswordInput\n name=\"password\"\n label=\"Password\"\n autoComplete=\"off\"\n required={true}\n error={getErrorsForInput(outcome, 'password')}\n />\n <Text color=\"dimmed\" size=\"xs\">\n By clicking submit you agree to the Medplum{' '}\n <Anchor href=\"https://www.medplum.com/privacy\">Privacy&nbsp;Policy</Anchor>\n {' and '}\n <Anchor href=\"https://www.medplum.com/terms\">Terms&nbsp;of&nbsp;Service</Anchor>.\n </Text>\n <Text color=\"dimmed\" size=\"xs\">\n This site is protected by reCAPTCHA and the Google{' '}\n <Anchor href=\"https://policies.google.com/privacy\">Privacy&nbsp;Policy</Anchor>\n {' and '}\n <Anchor href=\"https://policies.google.com/terms\">Terms&nbsp;of&nbsp;Service</Anchor> apply.\n </Text>\n </Stack>\n <Group position=\"apart\" mt=\"xl\" noWrap>\n <Checkbox name=\"remember\" label=\"Remember me\" size=\"xs\" />\n <Button type=\"submit\">Create account</Button>\n </Group>\n </Form>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;AA+BM,SAAU,WAAW,CAAC,KAAuB,EAAA;IACjD,MAAM,cAAc,GAAG,iBAAiB,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;AAC/D,IAAA,MAAM,gBAAgB,GAAG,KAAK,CAAC,gBAAgB,CAAC;AAChD,IAAA,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,CAAC,OAAO,E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,CAAA,aAAA,CAAA,IAAI,IAAC,KAAK,EAAC,QAAQ,EAAC,IAAI,EAAC,IAAI,EAAA;;gBACuB,GAAG;AACtD,gBAAA,KAAA,CAAA,aAAA,CAAC,MAAM,EAAA,EAAC,IAAI,EAAC,qCAAqC,EAA6B,EAAA,qBAAA,CAAA;gBAC9E,OAAO;AACR,gBAAA,KAAA,CAAA,aAAA,CAAC,MAAM,EAAA,EAAC,IAAI,EAAC,mCAAmC,EAAoC,EAAA,4BAAA,CAAA;0BAC/E,CACD;QACR,KAAC,CAAA,aAAA,CAAA,KAAK,EAAC,EAAA,QAAQ,EAAC,OAAO,EAAC,EAAE,EAAC,IAAI,EAAC,MAAM,EAAA,IAAA,EAAA;AACpC,YAAA,KAAA,CAAA,aAAA,CAAC,QAAQ,EAAA,EAAC,IAAI,EAAC,UAAU,EAAC,KAAK,EAAC,aAAa,EAAC,IAAI,EAAC,IAAI,EAAG,CAAA;YAC1D,KAAC,CAAA,aAAA,CAAA,MAAM,IAAC,IAAI,EAAC,QAAQ,EAAwB,EAAA,gBAAA,CAAA,CACvC,CACH,EACP;AACJ;;;;"}
1
+ {"version":3,"file":"NewUserForm.mjs","sources":["../../../src/auth/NewUserForm.tsx"],"sourcesContent":["import { Anchor, Button, Center, Checkbox, Divider, Group, PasswordInput, Stack, Text, TextInput } from '@mantine/core';\nimport { GoogleCredentialResponse, LoginAuthenticationResponse } from '@medplum/core';\nimport { OperationOutcome } from '@medplum/fhirtypes';\nimport React, { useEffect, 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';\nimport { getRecaptcha, initRecaptcha } from '../utils/recaptcha';\n\nexport interface NewUserFormProps {\n readonly projectId: string;\n readonly googleClientId?: string;\n readonly recaptchaSiteKey: string;\n readonly children?: React.ReactNode;\n readonly handleAuthResponse: (response: LoginAuthenticationResponse) => void;\n}\n\nexport function NewUserForm(props: NewUserFormProps): JSX.Element {\n const googleClientId = getGoogleClientId(props.googleClientId);\n const recaptchaSiteKey = props.recaptchaSiteKey;\n const medplum = useMedplum();\n const [outcome, setOutcome] = useState<OperationOutcome>();\n const issues = getIssuesForExpression(outcome, undefined);\n\n useEffect(() => initRecaptcha(recaptchaSiteKey), [recaptchaSiteKey]);\n\n return (\n <Form\n style={{ maxWidth: 400 }}\n onSubmit={async (formData: Record<string, string>) => {\n try {\n const recaptchaToken = await getRecaptcha(recaptchaSiteKey);\n props.handleAuthResponse(\n await medplum.startNewUser({\n projectId: props.projectId,\n firstName: formData.firstName,\n lastName: formData.lastName,\n email: formData.email,\n password: formData.password,\n remember: formData.remember === 'true',\n recaptchaSiteKey,\n recaptchaToken,\n })\n );\n } catch (err) {\n setOutcome(err as OperationOutcome);\n }\n }}\n >\n <Center sx={{ flexDirection: 'column' }}>{props.children}</Center>\n <OperationOutcomeAlert issues={issues} />\n {googleClientId && (\n <>\n <Group position=\"center\" p=\"xl\" style={{ height: 70 }}>\n <GoogleButton\n googleClientId={googleClientId}\n handleGoogleCredential={async (response: GoogleCredentialResponse) => {\n try {\n props.handleAuthResponse(\n await medplum.startGoogleLogin({\n googleClientId: response.clientId,\n googleCredential: response.credential,\n createUser: true,\n })\n );\n } catch (err) {\n setOutcome(err as OperationOutcome);\n }\n }}\n />\n </Group>\n <Divider label=\"or\" labelPosition=\"center\" my=\"lg\" />\n </>\n )}\n <Stack spacing=\"xl\">\n <TextInput\n name=\"firstName\"\n type=\"text\"\n label=\"First name\"\n placeholder=\"First name\"\n required={true}\n autoFocus={true}\n error={getErrorsForInput(outcome, 'firstName')}\n />\n <TextInput\n name=\"lastName\"\n type=\"text\"\n label=\"Last name\"\n placeholder=\"Last name\"\n required={true}\n error={getErrorsForInput(outcome, 'lastName')}\n />\n <TextInput\n name=\"email\"\n type=\"email\"\n label=\"Email\"\n placeholder=\"name@domain.com\"\n required={true}\n error={getErrorsForInput(outcome, 'email')}\n />\n <PasswordInput\n name=\"password\"\n label=\"Password\"\n autoComplete=\"off\"\n required={true}\n error={getErrorsForInput(outcome, 'password')}\n />\n <Text color=\"dimmed\" size=\"xs\">\n By clicking submit you agree to the Medplum{' '}\n <Anchor href=\"https://www.medplum.com/privacy\">Privacy&nbsp;Policy</Anchor>\n {' and '}\n <Anchor href=\"https://www.medplum.com/terms\">Terms&nbsp;of&nbsp;Service</Anchor>.\n </Text>\n <Text color=\"dimmed\" size=\"xs\">\n This site is protected by reCAPTCHA and the Google{' '}\n <Anchor href=\"https://policies.google.com/privacy\">Privacy&nbsp;Policy</Anchor>\n {' and '}\n <Anchor href=\"https://policies.google.com/terms\">Terms&nbsp;of&nbsp;Service</Anchor> apply.\n </Text>\n </Stack>\n <Group position=\"apart\" mt=\"xl\" noWrap>\n <Checkbox name=\"remember\" label=\"Remember me\" size=\"xs\" />\n <Button type=\"submit\">Create account</Button>\n </Group>\n </Form>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;AAmBM,SAAU,WAAW,CAAC,KAAuB,EAAA;IACjD,MAAM,cAAc,GAAG,iBAAiB,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;AAC/D,IAAA,MAAM,gBAAgB,GAAG,KAAK,CAAC,gBAAgB,CAAC;AAChD,IAAA,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,EAAoB,CAAC;IAC3D,MAAM,MAAM,GAAG,sBAAsB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AAE1D,IAAA,SAAS,CAAC,MAAM,aAAa,CAAC,gBAAgB,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;AAErE,IAAA,QACE,KAAC,CAAA,aAAA,CAAA,IAAI,IACH,KAAK,EAAE,EAAE,QAAQ,EAAE,GAAG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gBAAA,CAAA,CACvC,CACH,EACP;AACJ;;;;"}
@@ -1,6 +1,7 @@
1
1
  import { BaseLoginRequest } from '@medplum/core';
2
2
  import React from 'react';
3
3
  export interface SignInFormProps extends BaseLoginRequest {
4
+ readonly login?: string;
4
5
  readonly chooseScopes?: boolean;
5
6
  readonly onSuccess?: () => void;
6
7
  readonly onForgotPassword?: () => void;
@@ -1,4 +1,4 @@
1
- import React, { useState } from 'react';
1
+ import React, { useState, useCallback, useEffect } from 'react';
2
2
  import { Document } from '../Document/Document.mjs';
3
3
  import { useMedplum } from '../MedplumProvider/MedplumProvider.mjs';
4
4
  import { AuthenticationForm } from './AuthenticationForm.mjs';
@@ -23,7 +23,22 @@ function SignInForm(props) {
23
23
  const [login, setLogin] = useState(undefined);
24
24
  const [mfaRequired, setAuthenticatorRequired] = useState(false);
25
25
  const [memberships, setMemberships] = useState(undefined);
26
- function handleAuthResponse(response) {
26
+ const handleCode = useCallback((code) => {
27
+ if (onCode) {
28
+ onCode(code);
29
+ }
30
+ else {
31
+ medplum
32
+ .processCode(code)
33
+ .then(() => {
34
+ if (onSuccess) {
35
+ onSuccess();
36
+ }
37
+ })
38
+ .catch(console.log);
39
+ }
40
+ }, [medplum, onCode, onSuccess]);
41
+ const handleAuthResponse = useCallback((response) => {
27
42
  setAuthenticatorRequired(!!response.mfaRequired);
28
43
  if (response.login) {
29
44
  setLogin(response.login);
@@ -39,28 +54,21 @@ function SignInForm(props) {
39
54
  handleCode(response.code);
40
55
  }
41
56
  }
42
- }
43
- function handleScopeResponse(response) {
57
+ }, [chooseScopes, handleCode]);
58
+ const handleScopeResponse = useCallback((response) => {
44
59
  handleCode(response.code);
45
- }
46
- function handleCode(code) {
47
- if (onCode) {
48
- onCode(code);
49
- }
50
- else {
60
+ }, [handleCode]);
61
+ useEffect(() => {
62
+ if (props.login) {
51
63
  medplum
52
- .processCode(code)
53
- .then(() => {
54
- if (onSuccess) {
55
- onSuccess();
56
- }
57
- })
58
- .catch(console.log);
64
+ .get('auth/login/' + props.login)
65
+ .then(handleAuthResponse)
66
+ .catch(console.error);
59
67
  }
60
- }
68
+ }, [medplum, props, handleAuthResponse]);
61
69
  return (React.createElement(Document, { width: 450 }, (() => {
62
70
  if (!login) {
63
- return (React.createElement(AuthenticationForm, { generatePkce: !onCode, onForgotPassword: onForgotPassword, onRegister: onRegister, handleAuthResponse: handleAuthResponse, ...baseLoginRequest }, props.children));
71
+ return (React.createElement(AuthenticationForm, { onForgotPassword: onForgotPassword, onRegister: onRegister, handleAuthResponse: handleAuthResponse, ...baseLoginRequest }, props.children));
64
72
  }
65
73
  else if (mfaRequired) {
66
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, { 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 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 function handleAuthResponse(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\n function handleScopeResponse(response: LoginAuthenticationResponse): void {\n handleCode(response.code as string);\n }\n\n function handleCode(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\n return (\n <Document width={450}>\n {(() => {\n if (!login) {\n return (\n <AuthenticationForm\n generatePkce={!onCode}\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":";;;;;;;;;AAoBA;;;;;;;;;AASG;AACG,SAAU,UAAU,CAAC,KAAsB,EAAA;AAC/C,IAAA,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,gBAAg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GAAG,CACK,EACX;AACJ;;;;"}
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":";;;;;;;;;AAqBA;;;;;;;;;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,C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