@ampath/esm-login-app 8.0.0-next.20 → 8.0.0-next.21

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/routes.json CHANGED
@@ -1 +1 @@
1
- {"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"webservices.rest":">=2.2.0"},"pages":[{"component":"root","route":"login","online":true,"offline":true},{"component":"root","route":"logout","online":true,"offline":true},{"component":"root","route":"change-password","online":true,"offline":true}],"extensions":[{"name":"location-picker","slot":"location-picker","component":"locationPicker","online":true,"offline":true},{"name":"logout-button","slot":"user-panel-bottom-slot","component":"logoutButton","online":true,"offline":true},{"name":"password-changer","slot":"user-panel-slot","component":"changePasswordLink","online":true,"offline":true},{"name":"location-changer","slot":"top-nav-info-slot","component":"changeLocationLink","online":true,"offline":true,"order":1}],"modals":[{"name":"change-password-modal","component":"changePasswordModal"}],"version":"8.0.0-next.20"}
1
+ {"$schema":"https://json.openmrs.org/routes.schema.json","backendDependencies":{"webservices.rest":">=2.2.0"},"pages":[{"component":"root","route":"login","online":true,"offline":true},{"component":"root","route":"logout","online":true,"offline":true},{"component":"root","route":"change-password","online":true,"offline":true}],"extensions":[{"name":"location-picker","slot":"location-picker","component":"locationPicker","online":true,"offline":true},{"name":"logout-button","slot":"user-panel-bottom-slot","component":"logoutButton","online":true,"offline":true},{"name":"password-changer","slot":"user-panel-slot","component":"changePasswordLink","online":true,"offline":true},{"name":"location-changer","slot":"top-nav-info-slot","component":"changeLocationLink","online":true,"offline":true,"order":1}],"modals":[{"name":"change-password-modal","component":"changePasswordModal"}],"version":"8.0.0-next.21"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampath/esm-login-app",
3
- "version": "8.0.0-next.20",
3
+ "version": "8.0.0-next.21",
4
4
  "license": "MPL-2.0",
5
5
  "description": "The login microfrontend for the OpenMRS SPA",
6
6
  "browser": "dist/esm-login-app.js",
@@ -125,12 +125,13 @@ const Login: React.FC = () => {
125
125
  const uuid = session.user.person.uuid;
126
126
  try {
127
127
  const { email, phone } = await getEmailAndPhone(uuid, username, password);
128
- await getOtp(username, password, email, phone);
128
+ const res = await getOtp(username, password, email, phone);
129
129
  navigate('otp', {
130
130
  state: {
131
131
  username,
132
132
  password,
133
133
  referrer: location?.state?.referrer,
134
+ message: res,
134
135
  },
135
136
  });
136
137
  } catch (err: any) {
@@ -141,12 +142,13 @@ const Login: React.FC = () => {
141
142
  const uuid = session.user.person.uuid;
142
143
  const { email, phone } = await getEmailAndPhone(uuid, username, password);
143
144
  try {
144
- await getOtp(username, password, email, phone);
145
+ const res = await getOtp(username, password, email, phone);
145
146
  navigate('otp', {
146
147
  state: {
147
148
  username,
148
149
  password,
149
150
  referrer: location?.state?.referrer,
151
+ message: res,
150
152
  },
151
153
  });
152
154
  } catch (err: any) {
@@ -20,7 +20,7 @@ const OtpComponent: React.FC = () => {
20
20
  const { t } = useTranslation();
21
21
  const location = useLocation();
22
22
 
23
- const { username, password } = location.state || {};
23
+ const { username, password, message } = location.state || {};
24
24
 
25
25
  const handleOtpChange = (val: React.SetStateAction<string>) => {
26
26
  setOtpValue(val);
@@ -50,10 +50,13 @@ const OtpComponent: React.FC = () => {
50
50
 
51
51
  let to = '/home';
52
52
  if (location.state?.referrer) {
53
- to = location.state.referrer.startsWith('/')
54
- ? `\${openmrsSpaBase}${location.state.referrer}`
55
- : location.state.referrer;
53
+ to = location.state.referrer;
56
54
  }
55
+ // if (location.state?.referrer) {
56
+ // to = location.state.referrer.startsWith('/')
57
+ // ? `\${openmrsSpaBase}${location.state.referrer}`
58
+ // : location.state.referrer;
59
+ // }
57
60
 
58
61
  navigate(to);
59
62
  } else {
@@ -84,9 +87,7 @@ const OtpComponent: React.FC = () => {
84
87
  </div>
85
88
  <div className={styles.container}>
86
89
  <h2 className={styles.header}>OTP</h2>
87
- <p>
88
- Please Check your email <br /> and enter your One Time Password
89
- </p>
90
+ <p>{message || 'Enter the OTP sent to your registered email and phone number to complete login.'}</p>
90
91
  <OTPInput length={5} onChange={handleOtpChange} />
91
92
  {error && (
92
93
  <InlineNotification
@@ -1,12 +1,12 @@
1
1
  import { openmrsFetch } from '@openmrs/esm-framework';
2
- import { getEtlBaseUrl, getSubDomain } from '../utils/get-base-url';
2
+ import { getEtlBaseUrl, getOtpKey, getSubDomain } from '../utils/get-base-url';
3
3
 
4
4
  const EMAIL_ATTRIBUTE_TYPE_UUID = 'ecabe213-160b-11ef-ad65-a0d3c1fcd41c';
5
5
  const PHONE_NUMBER_ATTRIBUTE_TYPE_UUID = '72a759a8-1359-11df-a1f1-0026b9348838';
6
6
 
7
7
  type ContactInfo = {
8
- email: string | null;
9
- phone: string | null;
8
+ email?: string | null;
9
+ phone?: string | null;
10
10
  };
11
11
 
12
12
  export async function getEmailAndPhone(uuid: string, username: string, password: string): Promise<ContactInfo> {
@@ -37,15 +37,15 @@ export async function getEmailAndPhone(uuid: string, username: string, password:
37
37
  const phoneAttr = data.attributes?.find(
38
38
  (attr) => !attr.voided && attr.attributeType?.uuid === PHONE_NUMBER_ATTRIBUTE_TYPE_UUID,
39
39
  );
40
- const email = emailAttr?.value;
41
- const phone = phoneAttr?.value;
40
+ const email = emailAttr?.value ?? null;
41
+ const phone = phoneAttr?.value ?? null;
42
42
 
43
- if (email === undefined || email === null) {
44
- throw new Error('Your email has not been configured. Please contact system administrator for assistance.');
45
- }
46
- if (phone === undefined || phone === null) {
47
- throw new Error('Your phone number has not been configured. Please contact system administrator for assistance.');
43
+ if (!email && !phone) {
44
+ throw new Error(
45
+ 'Neither email nor phone number has been configured. Please contact system administrator for assistance.',
46
+ );
48
47
  }
48
+
49
49
  return { email, phone };
50
50
  } catch (error) {
51
51
  throw new Error(error.message ?? 'Failed to fetch contact info');
@@ -54,7 +54,8 @@ export async function getEmailAndPhone(uuid: string, username: string, password:
54
54
 
55
55
  export async function getOtp(username: string, password: string, email: string, phone: string) {
56
56
  const etlBaseUrl = await getEtlBaseUrl();
57
- const params = new URLSearchParams({ username, email, phone });
57
+ const key = await getOtpKey();
58
+ const params = new URLSearchParams({ username, email, phone, key });
58
59
  const credentials = window.btoa(`${username}:${password}`);
59
60
 
60
61
  try {
@@ -73,7 +74,7 @@ export async function getOtp(username: string, password: string, email: string,
73
74
  throw new Error(data.message);
74
75
  }
75
76
 
76
- return data.data.message;
77
+ return data.data;
77
78
  } catch (error) {
78
79
  throw new Error(error.message);
79
80
  }
@@ -15,3 +15,8 @@ export async function getSubDomain() {
15
15
  const { subDomain } = await getConfig(moduleName);
16
16
  return subDomain ?? null;
17
17
  }
18
+
19
+ export async function getOtpKey() {
20
+ const { otpKey } = await getConfig(moduleName);
21
+ return otpKey ?? null;
22
+ }