@beinformed/ui 1.18.3 → 1.18.6

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.
Files changed (236) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/esm/constants/Constants.js +1 -0
  3. package/esm/constants/Constants.js.map +1 -1
  4. package/esm/constants/Settings.js +10 -3
  5. package/esm/constants/Settings.js.map +1 -1
  6. package/esm/hooks/useAuthentication.js +7 -50
  7. package/esm/hooks/useAuthentication.js.map +1 -1
  8. package/esm/i18n/Locales.js.map +1 -1
  9. package/esm/models/concepts/ConceptDetailModel.js.map +1 -1
  10. package/esm/models/form/FormModel.js +3 -1
  11. package/esm/models/form/FormModel.js.map +1 -1
  12. package/esm/models/layouthint/LayoutHintCollection.js.map +1 -1
  13. package/esm/models/tab/TabModel.js.map +1 -1
  14. package/esm/modularui/Authenticate.js +100 -21
  15. package/esm/modularui/Authenticate.js.map +1 -1
  16. package/esm/redux/actions/Preferences.js +2 -2
  17. package/esm/redux/actions/Preferences.js.map +1 -1
  18. package/esm/redux/actions/SignOut.js +6 -2
  19. package/esm/redux/actions/SignOut.js.map +1 -1
  20. package/esm/redux/connectors/SignIn.js +3 -2
  21. package/esm/redux/connectors/SignIn.js.map +1 -1
  22. package/esm/redux/connectors/SignOut.js +4 -1
  23. package/esm/redux/connectors/SignOut.js.map +1 -1
  24. package/esm/redux/reducers/AuthReducer.js +0 -10
  25. package/esm/redux/reducers/AuthReducer.js.map +1 -1
  26. package/esm/redux/types.js.map +1 -1
  27. package/esm/utils/helpers/checkResource.js +2 -0
  28. package/esm/utils/helpers/checkResource.js.map +1 -1
  29. package/lib/constants/Constants.js +3 -1
  30. package/lib/constants/Constants.js.flow +1 -0
  31. package/lib/constants/Constants.js.map +1 -1
  32. package/lib/constants/LayoutHints.js.map +1 -1
  33. package/lib/constants/Settings.js +13 -3
  34. package/lib/constants/Settings.js.flow +8 -3
  35. package/lib/constants/Settings.js.map +1 -1
  36. package/lib/exceptions/FetchException.js.map +1 -1
  37. package/lib/hooks/__tests__/useAuthentication.spec.js.flow +15 -1
  38. package/lib/hooks/useAllFormsOnModel.js.map +1 -1
  39. package/lib/hooks/useAuthentication.js +7 -55
  40. package/lib/hooks/useAuthentication.js.flow +4 -37
  41. package/lib/hooks/useAuthentication.js.map +1 -1
  42. package/lib/hooks/useContent.js.map +1 -1
  43. package/lib/hooks/useDeepCompareEffect.js.map +1 -1
  44. package/lib/hooks/useForm.js.map +1 -1
  45. package/lib/hooks/useI18n.js.map +1 -1
  46. package/lib/hooks/useModal.js.map +1 -1
  47. package/lib/hooks/useModelCatalog.js.map +1 -1
  48. package/lib/hooks/useModels.js.map +1 -1
  49. package/lib/hooks/useModularUI.js.map +1 -1
  50. package/lib/hooks/useModularUIBasic.js.map +1 -1
  51. package/lib/hooks/useModularUIModel.js.map +1 -1
  52. package/lib/hooks/useModularUIRequest.js.map +1 -1
  53. package/lib/hooks/useNotification.js.map +1 -1
  54. package/lib/hooks/usePreference.js.map +1 -1
  55. package/lib/hooks/useProgressIndicator.js.map +1 -1
  56. package/lib/hooks/useRouter.js.map +1 -1
  57. package/lib/i18n/Locale.js.map +1 -1
  58. package/lib/i18n/Locales.js.map +1 -1
  59. package/lib/i18n/Message.js.map +1 -1
  60. package/lib/i18n/withMessage.js.map +1 -1
  61. package/lib/models/actions/ActionModel.js.map +1 -1
  62. package/lib/models/application/ApplicationModel.js.map +1 -1
  63. package/lib/models/attributes/AttributeCollection.js.map +1 -1
  64. package/lib/models/attributes/AttributeContent.js.map +1 -1
  65. package/lib/models/attributes/AttributeDataHelper.js.map +1 -1
  66. package/lib/models/attributes/AttributeModel.js.map +1 -1
  67. package/lib/models/attributes/AttributeSetModel.js.map +1 -1
  68. package/lib/models/attributes/BooleanAttributeModel.js.map +1 -1
  69. package/lib/models/attributes/ChoiceAttributeModel.js.map +1 -1
  70. package/lib/models/attributes/ChoiceAttributeOptionCollection.js.map +1 -1
  71. package/lib/models/attributes/ChoiceAttributeOptionModel.js.map +1 -1
  72. package/lib/models/attributes/CompositeAttributeChildCollection.js.map +1 -1
  73. package/lib/models/attributes/CompositeAttributeModel.js.map +1 -1
  74. package/lib/models/attributes/DatetimeAttributeModel.js.map +1 -1
  75. package/lib/models/attributes/HelptextAttributeModel.js.map +1 -1
  76. package/lib/models/attributes/MemoAttributeModel.js.map +1 -1
  77. package/lib/models/attributes/MoneyAttributeModel.js.map +1 -1
  78. package/lib/models/attributes/NumberAttributeModel.js.map +1 -1
  79. package/lib/models/attributes/StringAttributeModel.js.map +1 -1
  80. package/lib/models/attributes/XMLAttributeModel.js.map +1 -1
  81. package/lib/models/attributes/_createAttribute.js.map +1 -1
  82. package/lib/models/attributes/input-constraints/ConstraintCollection.js.map +1 -1
  83. package/lib/models/attributes/input-constraints/ConstraintModel.js.map +1 -1
  84. package/lib/models/attributes/input-constraints/DateTimeDateFormatConstraint.js.map +1 -1
  85. package/lib/models/attributes/input-constraints/DateTimeTimeFormatConstraint.js.map +1 -1
  86. package/lib/models/attributes/input-constraints/FileSizeConstraint.js.map +1 -1
  87. package/lib/models/attributes/input-constraints/IBANConstraint.js.map +1 -1
  88. package/lib/models/attributes/input-constraints/NumberBoundaryConstraint.js.map +1 -1
  89. package/lib/models/attributes/input-constraints/NumberFormatConstraint.js.map +1 -1
  90. package/lib/models/base/BaseCollection.js.map +1 -1
  91. package/lib/models/base/BaseModel.js.map +1 -1
  92. package/lib/models/caseview/CaseViewModel.js.map +1 -1
  93. package/lib/models/concepts/BusinessScenarioModel.js.map +1 -1
  94. package/lib/models/concepts/ConceptDetailModel.js.map +1 -1
  95. package/lib/models/concepts/ConceptLinkModel.js.map +1 -1
  96. package/lib/models/concepts/SourceReferenceModel.js.map +1 -1
  97. package/lib/models/content/ContentLinkModel.js.map +1 -1
  98. package/lib/models/content/ContentTOCModel.js.map +1 -1
  99. package/lib/models/content/SectionModel.js.map +1 -1
  100. package/lib/models/content/SubSectionModel.js.map +1 -1
  101. package/lib/models/contentconfiguration/ContentConfigurationResults.js.map +1 -1
  102. package/lib/models/detail/DetailModel.js.map +1 -1
  103. package/lib/models/filters/BaseFilterModel.js.map +1 -1
  104. package/lib/models/form/FormModel.js +3 -1
  105. package/lib/models/form/FormModel.js.flow +1 -1
  106. package/lib/models/form/FormModel.js.map +1 -1
  107. package/lib/models/form/FormObjectModel.js.map +1 -1
  108. package/lib/models/href/Href.js.map +1 -1
  109. package/lib/models/layouthint/LayoutHintCollection.js.map +1 -1
  110. package/lib/models/links/LinkCollection.js.map +1 -1
  111. package/lib/models/links/LinkModel.js.map +1 -1
  112. package/lib/models/list/ListDetailModel.js.map +1 -1
  113. package/lib/models/list/ListHeaderModel.js.map +1 -1
  114. package/lib/models/list/ListItemCollection.js.map +1 -1
  115. package/lib/models/list/ListModel.js.map +1 -1
  116. package/lib/models/lookup/LookupOptionsModel.js.map +1 -1
  117. package/lib/models/paging/PagingModel.js.map +1 -1
  118. package/lib/models/panels/GroupingPanelModel.js.map +1 -1
  119. package/lib/models/parameter/Parameter.js.map +1 -1
  120. package/lib/models/process/ProcessStatusSettingsModel.js.map +1 -1
  121. package/lib/models/resolveModel.js.map +1 -1
  122. package/lib/models/sorting/SortingModel.js.map +1 -1
  123. package/lib/models/tab/TabModel.js.map +1 -1
  124. package/lib/models/user/UserProfileModel.js.map +1 -1
  125. package/lib/models/user/UserServicesModel.js.map +1 -1
  126. package/lib/modularui/Authenticate.js +102 -21
  127. package/lib/modularui/Authenticate.js.flow +75 -20
  128. package/lib/modularui/Authenticate.js.map +1 -1
  129. package/lib/modularui/ModularUIRequest.js.map +1 -1
  130. package/lib/modularui/ModularUIResponse.js.map +1 -1
  131. package/lib/react/ErrorBoundaryFallback.js.map +1 -1
  132. package/lib/react-client/client.js.map +1 -1
  133. package/lib/react-client/rehydrate.js.map +1 -1
  134. package/lib/react-server/__tests__/serverUtil.spec.js.flow +6 -4
  135. package/lib/react-server/createSSRComplete.js.map +1 -1
  136. package/lib/react-server/renderSSRComplete.js.map +1 -1
  137. package/lib/react-server/renderSSRMinimal.js.map +1 -1
  138. package/lib/react-server/serverNoSSR.js.map +1 -1
  139. package/lib/react-server/serverSSR.js.map +1 -1
  140. package/lib/react-server/serverUtil.js.map +1 -1
  141. package/lib/react-theme/ThemeProvider.js.map +1 -1
  142. package/lib/react-theme/createTheme.js.map +1 -1
  143. package/lib/react-theme/useTheme.js.map +1 -1
  144. package/lib/react-theme/utils/background.js.map +1 -1
  145. package/lib/react-theme/utils/colors.js.map +1 -1
  146. package/lib/react-theme/utils/contrast.js.map +1 -1
  147. package/lib/react-theme/utils/corners.js.map +1 -1
  148. package/lib/react-theme/utils/spacers.js.map +1 -1
  149. package/lib/react-theme/utils/themeProps.js.map +1 -1
  150. package/lib/redux/_i18n/actions.js.map +1 -1
  151. package/lib/redux/_i18n/reducer.js.map +1 -1
  152. package/lib/redux/_modularui/actions.js.map +1 -1
  153. package/lib/redux/_modularui/connector.js.map +1 -1
  154. package/lib/redux/_modularui/middleware.js.map +1 -1
  155. package/lib/redux/_modularui/modularuiUtils.js.map +1 -1
  156. package/lib/redux/_modularui/reducer.js.map +1 -1
  157. package/lib/redux/_modularui/selectors.js.map +1 -1
  158. package/lib/redux/_modularui/withModularUI.js.map +1 -1
  159. package/lib/redux/_router/connectors.js.map +1 -1
  160. package/lib/redux/actions/Application.js.map +1 -1
  161. package/lib/redux/actions/Authorization.js.map +1 -1
  162. package/lib/redux/actions/Error.js.map +1 -1
  163. package/lib/redux/actions/Form.js.map +1 -1
  164. package/lib/redux/actions/FormAttributeSet.js.map +1 -1
  165. package/lib/redux/actions/FormAttributeSetRepeatable.js.map +1 -1
  166. package/lib/redux/actions/FormAutosave.js.map +1 -1
  167. package/lib/redux/actions/FormAutosubmit.js.map +1 -1
  168. package/lib/redux/actions/FormValidations.js.map +1 -1
  169. package/lib/redux/actions/Notification.js.map +1 -1
  170. package/lib/redux/actions/Preferences.js +1 -1
  171. package/lib/redux/actions/Preferences.js.flow +7 -3
  172. package/lib/redux/actions/Preferences.js.map +1 -1
  173. package/lib/redux/actions/SignIn.js.map +1 -1
  174. package/lib/redux/actions/SignOut.js +6 -1
  175. package/lib/redux/actions/SignOut.js.flow +9 -5
  176. package/lib/redux/actions/SignOut.js.map +1 -1
  177. package/lib/redux/connectors/Application.js.map +1 -1
  178. package/lib/redux/connectors/Breadcrumb.js.map +1 -1
  179. package/lib/redux/connectors/CaseView.js.map +1 -1
  180. package/lib/redux/connectors/ConceptDetail.js.map +1 -1
  181. package/lib/redux/connectors/ContentBrowser.js.map +1 -1
  182. package/lib/redux/connectors/ContentDetail.js.map +1 -1
  183. package/lib/redux/connectors/ContentDetailSection.js.map +1 -1
  184. package/lib/redux/connectors/Form.js.map +1 -1
  185. package/lib/redux/connectors/FormAttributeSet.js.map +1 -1
  186. package/lib/redux/connectors/ListDetail.js.map +1 -1
  187. package/lib/redux/connectors/Modal.js.map +1 -1
  188. package/lib/redux/connectors/ModelCatalog.js.map +1 -1
  189. package/lib/redux/connectors/Notification.js.map +1 -1
  190. package/lib/redux/connectors/PanelRenderer.js.map +1 -1
  191. package/lib/redux/connectors/Preferences.js.map +1 -1
  192. package/lib/redux/connectors/Progress.js.map +1 -1
  193. package/lib/redux/connectors/ProgressIndicator.js.map +1 -1
  194. package/lib/redux/connectors/QuickSearch.js.map +1 -1
  195. package/lib/redux/connectors/SignIn.js +3 -5
  196. package/lib/redux/connectors/SignIn.js.flow +1 -6
  197. package/lib/redux/connectors/SignIn.js.map +1 -1
  198. package/lib/redux/connectors/SignOut.js +5 -1
  199. package/lib/redux/connectors/SignOut.js.flow +2 -1
  200. package/lib/redux/connectors/SignOut.js.map +1 -1
  201. package/lib/redux/connectors/Tab.js.map +1 -1
  202. package/lib/redux/reducers/AuthReducer.js +0 -11
  203. package/lib/redux/reducers/AuthReducer.js.flow +0 -11
  204. package/lib/redux/reducers/AuthReducer.js.map +1 -1
  205. package/lib/redux/reducers/__tests__/AuthReducer.spec.js.flow +0 -9
  206. package/lib/redux/store/configureStore.js.map +1 -1
  207. package/lib/redux/types.js.flow +0 -1
  208. package/lib/redux/types.js.map +1 -1
  209. package/lib/utils/browser/Cookies.js.map +1 -1
  210. package/lib/utils/datetime/DateTimeUtil.js.map +1 -1
  211. package/lib/utils/fetch/universalFetch.js.map +1 -1
  212. package/lib/utils/fetch/xhr.js.map +1 -1
  213. package/lib/utils/helpers/checkResource.js +2 -0
  214. package/lib/utils/helpers/checkResource.js.flow +3 -0
  215. package/lib/utils/helpers/checkResource.js.map +1 -1
  216. package/lib/utils/helpers/objects.js.map +1 -1
  217. package/lib/utils/helpers/sanitizeHtml.js.map +1 -1
  218. package/lib/utils/helpers/text.js.map +1 -1
  219. package/lib/utils/number/formatValue.js.map +1 -1
  220. package/lib/utils/number/parseNumbers.js.map +1 -1
  221. package/package.json +22 -22
  222. package/src/constants/Constants.js +1 -0
  223. package/src/constants/Settings.js +8 -3
  224. package/src/hooks/__tests__/useAuthentication.spec.js +15 -1
  225. package/src/hooks/useAuthentication.js +4 -37
  226. package/src/models/form/FormModel.js +1 -1
  227. package/src/modularui/Authenticate.js +75 -20
  228. package/src/react-server/__tests__/serverUtil.spec.js +6 -4
  229. package/src/redux/actions/Preferences.js +7 -3
  230. package/src/redux/actions/SignOut.js +9 -5
  231. package/src/redux/connectors/SignIn.js +1 -6
  232. package/src/redux/connectors/SignOut.js +2 -1
  233. package/src/redux/reducers/AuthReducer.js +0 -11
  234. package/src/redux/reducers/__tests__/AuthReducer.spec.js +0 -9
  235. package/src/redux/types.js +0 -1
  236. package/src/utils/helpers/checkResource.js +3 -0
@@ -5,10 +5,10 @@ import universalFetch from "../utils/fetch/universalFetch";
5
5
  import Cache from "../utils/browser/Cache";
6
6
 
7
7
  import { UnauthorizedException } from "../exceptions";
8
- import type { RequestOptions } from "../utils/fetch/types";
9
8
  import {
10
- loginPasswordField,
9
+ loginType,
11
10
  loginPath,
11
+ loginPasswordField,
12
12
  loginUsernameField,
13
13
  logoutPath,
14
14
  } from "../constants";
@@ -24,10 +24,27 @@ class Authenticate {
24
24
  this._isBasic = false;
25
25
  }
26
26
 
27
+ /**
28
+ */
29
+ get authenticationType(): "JAAS" | "PAC4J_FORM" | "PAC4J_BASIC" {
30
+ const type = loginType();
31
+
32
+ if (!type || type === "JAAS") {
33
+ return "JAAS";
34
+ }
35
+ if (type.includes("FormClient")) {
36
+ return "PAC4J_FORM";
37
+ } else if (type.includes("BasicClient")) {
38
+ return "PAC4J_BASIC";
39
+ }
40
+
41
+ throw new Error(`Unsupported login type found: ${type}`);
42
+ }
43
+
27
44
  /**
28
45
  */
29
46
  get isBasicAuthentication(): boolean {
30
- return this._isBasic;
47
+ return this._isBasic || this.authenticationType === "PAC4J_BASIC";
31
48
  }
32
49
 
33
50
  /**
@@ -64,47 +81,85 @@ class Authenticate {
64
81
 
65
82
  /**
66
83
  */
67
- createLogin(username: string, password: string): $Shape<RequestOptions> {
68
- const LOGIN_PATH = loginPath();
69
- const usernameField = loginUsernameField();
70
- const passwordField = loginPasswordField();
84
+ login(username: string, password: string): Promise<any> {
85
+ switch (this.authenticationType) {
86
+ case "PAC4J_FORM":
87
+ return this.doFormLogin(username, password);
88
+ case "PAC4J_BASIC":
89
+ return this.doBasicAuthentication(username, password);
90
+ default:
91
+ return this.doJaasAuthentication(username, password);
92
+ }
93
+ }
94
+
95
+ /**
96
+ */
97
+ getFormLoginUrl(): string {
98
+ switch (this.authenticationType) {
99
+ case "PAC4J_BASIC":
100
+ case "PAC4J_FORM":
101
+ return `${BASE}${loginPath()}`;
102
+ default:
103
+ return `${BASE}/j_security_check`;
104
+ }
105
+ }
71
106
 
107
+ /**
108
+ */
109
+ getFormLoginData(username: string, password: string): string {
72
110
  const encodedUsername = encodeURIComponent(username);
73
111
  const encodedPassword = encodeURIComponent(password);
74
112
 
75
- return {
76
- url: LOGIN_PATH,
113
+ switch (this.authenticationType) {
114
+ case "PAC4J_BASIC":
115
+ case "PAC4J_FORM":
116
+ return `${loginUsernameField()}=${encodedUsername}&${loginPasswordField()}=${encodedPassword}`;
117
+ default:
118
+ return `j_username=${encodedUsername}&j_password=${encodedPassword}`;
119
+ }
120
+ }
121
+
122
+ /**
123
+ */
124
+ doFormLogin(username: string, password: string): Promise<any> {
125
+ return universalFetch({
126
+ url: this.getFormLoginUrl(),
77
127
  method: HTTP_METHODS.POST,
78
128
  headers: {
79
129
  Accept: "application/json",
80
130
  "Content-Type": "application/x-www-form-urlencoded",
81
131
  },
82
- data: `${usernameField}=${encodedUsername}&${passwordField}=${encodedPassword}`,
83
- };
132
+ data: this.getFormLoginData(username, password),
133
+ });
84
134
  }
85
135
 
86
136
  /**
87
137
  */
88
- login(username: string, password: string): Promise<any> {
138
+ doBasicAuthentication(username: string, password: string): Promise<any> {
139
+ Cache.addItem("basic", btoa(`${username}:${password}`));
140
+ return Promise.resolve();
141
+ }
142
+
143
+ /**
144
+ */
145
+ doJaasAuthentication(username: string, password: string): Promise<any> {
89
146
  return this.initLogin(true).then(() => {
90
147
  if (this.isBasicAuthentication) {
91
- Cache.addItem("basic", btoa(`${username}:${password}`));
92
-
93
- return Promise.resolve();
148
+ return this.doBasicAuthentication(username, password);
94
149
  }
95
-
96
- return universalFetch(this.createLogin(username, password));
150
+ return this.doFormLogin(username, password);
97
151
  });
98
152
  }
99
153
 
100
154
  /**
101
155
  */
102
- logout(): Promise<void> {
156
+ logout(): Promise<any> {
103
157
  return universalFetch({
104
- url: logoutPath(),
105
- }).then(() => {
158
+ url: `${BASE}${logoutPath()}`,
159
+ }).then((response) => {
106
160
  // clear cache because of cached contributions
107
161
  Cache.clear();
162
+ return response;
108
163
  });
109
164
  }
110
165
  }
@@ -112,10 +112,11 @@ describe("serverUtil", () => {
112
112
  {
113
113
  type: "SET_PREFERENCES",
114
114
  payload: {
115
- "FormClient.login_url": "/BeInformed/j_security_check",
116
- "FormClient.logout_url": "/BeInformed/Logoff",
115
+ "FormClient.login_url": "/j_security_check",
116
+ "FormClient.logout_url": "/Logoff",
117
117
  "FormClient.password_field_name": "j_password",
118
118
  "FormClient.username_field_name": "j_username",
119
+ "security.clients": null,
119
120
  },
120
121
  },
121
122
  ]);
@@ -158,10 +159,11 @@ describe("serverUtil", () => {
158
159
  {
159
160
  type: "SET_PREFERENCES",
160
161
  payload: {
161
- "FormClient.login_url": "/BeInformed/j_security_check",
162
- "FormClient.logout_url": "/BeInformed/Logoff",
162
+ "FormClient.login_url": "/j_security_check",
163
+ "FormClient.logout_url": "/Logoff",
163
164
  "FormClient.password_field_name": "j_password",
164
165
  "FormClient.username_field_name": "j_username",
166
+ "security.clients": null,
165
167
  },
166
168
  },
167
169
  ]);
@@ -12,8 +12,8 @@ import type {
12
12
  } from "../types";
13
13
 
14
14
  import {
15
- BASE,
16
15
  ALL_CONTENT_IN_DATA_SETTING,
16
+ LOGIN_TYPE,
17
17
  LOGIN_PASSWORD_SETTING,
18
18
  LOGIN_PATH_SETTING,
19
19
  LOGIN_USERNAME_SETTING,
@@ -123,9 +123,13 @@ export const setLoginPreferences = (
123
123
  state?: ReduxState
124
124
  ): SetPreferencesAction => {
125
125
  const loginSettings = {
126
+ [LOGIN_TYPE]: getServerPreferenceValue(
127
+ LOGIN_TYPE,
128
+ state?.preferences[LOGIN_TYPE]
129
+ ),
126
130
  [LOGIN_PATH_SETTING]: getServerPreferenceValue(
127
131
  LOGIN_PATH_SETTING,
128
- state?.preferences[LOGIN_PATH_SETTING] ?? `${BASE}/j_security_check`
132
+ state?.preferences[LOGIN_PATH_SETTING] ?? `/j_security_check`
129
133
  ),
130
134
  [LOGIN_USERNAME_SETTING]: getServerPreferenceValue(
131
135
  LOGIN_USERNAME_SETTING,
@@ -137,7 +141,7 @@ export const setLoginPreferences = (
137
141
  ),
138
142
  [LOGOUT_PATH_SETTING]: getServerPreferenceValue(
139
143
  LOGOUT_PATH_SETTING,
140
- state?.preferences[LOGOUT_PATH_SETTING] ?? `${BASE}/Logoff`
144
+ state?.preferences[LOGOUT_PATH_SETTING] ?? `/Logoff`
141
145
  ),
142
146
  };
143
147
 
@@ -4,6 +4,7 @@ import { startProgress, finishProgress } from "./ProgressIndicator";
4
4
  import { resetModularUI } from "../_modularui/actions";
5
5
 
6
6
  import type { Dispatch, LogoutSuccessAction, ThunkAction } from "../types";
7
+ import { reloadApplication } from "./Application";
7
8
 
8
9
  /**
9
10
  * Send logout success action
@@ -17,9 +18,12 @@ export const logoutSuccess = (): LogoutSuccessAction => ({
17
18
  export const logout = (): ThunkAction => (dispatch: Dispatch) => {
18
19
  dispatch(startProgress());
19
20
 
20
- return new Authenticate().logout().then(() => {
21
- dispatch(resetModularUI());
22
- dispatch(logoutSuccess());
23
- return dispatch(finishProgress());
24
- });
21
+ return new Authenticate()
22
+ .logout()
23
+ .then(() => dispatch(resetModularUI()))
24
+ .then(() => dispatch(reloadApplication()))
25
+ .then(() => {
26
+ dispatch(logoutSuccess());
27
+ return dispatch(finishProgress());
28
+ });
25
29
  };
@@ -5,8 +5,6 @@ import { login } from "../actions/SignIn";
5
5
 
6
6
  import { getApplication } from "../_modularui/selectors";
7
7
 
8
- import UserServicesModel from "../../models/user/UserServicesModel";
9
-
10
8
  import type { ReduxState, ThunkAction } from "../types";
11
9
  import type { ComponentType } from "react";
12
10
 
@@ -28,10 +26,7 @@ const mapStateToProps = (state: ReduxState): StateProps => {
28
26
  const application = getApplication(state);
29
27
 
30
28
  return {
31
- isAuthenticated:
32
- state.auth.isAuthenticated &&
33
- application?.userServices instanceof UserServicesModel &&
34
- application.userServices.isLoggedIn,
29
+ isAuthenticated: application?.isLoggedIn ?? false,
35
30
  errorMessage: state.auth.error,
36
31
  };
37
32
  };
@@ -5,6 +5,7 @@ import { logout } from "../actions/SignOut";
5
5
 
6
6
  import type { ThunkAction } from "../types";
7
7
  import type { ComponentType } from "react";
8
+ import { getApplication } from "../_modularui";
8
9
 
9
10
  type StateProps = {
10
11
  isAuthenticated: boolean,
@@ -20,7 +21,7 @@ type Props = {
20
21
  };
21
22
 
22
23
  const mapStateToProps = (state): StateProps => ({
23
- isAuthenticated: state.auth.isAuthenticated,
24
+ isAuthenticated: getApplication(state)?.isLoggedIn ?? false,
24
25
  });
25
26
 
26
27
  const mapDispatchToProps = { doLogout: logout };
@@ -1,12 +1,9 @@
1
1
  // @flow
2
- import Cache from "../../utils/browser/Cache";
3
-
4
2
  import type { Reducer } from "redux";
5
3
  import type { AuthState, ReduxAction } from "../types";
6
4
 
7
5
  // REDUCER
8
6
  const initialState: AuthState = {
9
- isAuthenticated: false,
10
7
  mustChangePassword: false,
11
8
  error: null,
12
9
  };
@@ -26,7 +23,6 @@ const AuthReducer: Reducer<AuthState, ReduxAction> = (
26
23
  case "AUTHENTICATION_SUCCESS":
27
24
  return {
28
25
  ...state,
29
- isAuthenticated: true,
30
26
  error: null,
31
27
  mustChangePassword: false,
32
28
  };
@@ -38,15 +34,9 @@ const AuthReducer: Reducer<AuthState, ReduxAction> = (
38
34
  return { ...state, error: null };
39
35
 
40
36
  case "AUTHENTICATION_LOGOUT": {
41
- // clear cache because of cached contributions
42
- if (state.isAuthenticated) {
43
- Cache.clear();
44
- }
45
-
46
37
  return {
47
38
  ...state,
48
39
  mustChangePassword: false,
49
- isAuthenticated: false,
50
40
  error: null,
51
41
  };
52
42
  }
@@ -54,7 +44,6 @@ const AuthReducer: Reducer<AuthState, ReduxAction> = (
54
44
  case "CHANGE_PASSWORD":
55
45
  return {
56
46
  ...state,
57
- isAuthenticated: true,
58
47
  mustChangePassword: true,
59
48
  error: null,
60
49
  };
@@ -3,13 +3,11 @@ import AuthReducer from "../AuthReducer";
3
3
  describe("authentication reducer", () => {
4
4
  it("should return the initial state", () => {
5
5
  expect(AuthReducer(undefined, {})).toStrictEqual({
6
- isAuthenticated: false,
7
6
  mustChangePassword: false,
8
7
  error: null,
9
8
  });
10
9
 
11
10
  expect(AuthReducer()).toStrictEqual({
12
- isAuthenticated: false,
13
11
  mustChangePassword: false,
14
12
  error: null,
15
13
  });
@@ -24,7 +22,6 @@ describe("authentication reducer", () => {
24
22
  }
25
23
  )
26
24
  ).toStrictEqual({
27
- isAuthenticated: true,
28
25
  mustChangePassword: false,
29
26
  error: null,
30
27
  });
@@ -49,7 +46,6 @@ describe("authentication reducer", () => {
49
46
  expect(
50
47
  AuthReducer(
51
48
  {
52
- isAuthenticated: true,
53
49
  mustChangePassword: false,
54
50
  error: null,
55
51
  },
@@ -58,7 +54,6 @@ describe("authentication reducer", () => {
58
54
  }
59
55
  )
60
56
  ).toStrictEqual({
61
- isAuthenticated: false,
62
57
  mustChangePassword: false,
63
58
  error: null,
64
59
  });
@@ -68,7 +63,6 @@ describe("authentication reducer", () => {
68
63
  expect(
69
64
  AuthReducer(
70
65
  {
71
- isAuthenticated: false,
72
66
  mustChangePassword: false,
73
67
  error: "In error",
74
68
  },
@@ -77,7 +71,6 @@ describe("authentication reducer", () => {
77
71
  }
78
72
  )
79
73
  ).toStrictEqual({
80
- isAuthenticated: false,
81
74
  mustChangePassword: false,
82
75
  error: null,
83
76
  });
@@ -87,7 +80,6 @@ describe("authentication reducer", () => {
87
80
  expect(
88
81
  AuthReducer(
89
82
  {
90
- isAuthenticated: true,
91
83
  mustChangePassword: false,
92
84
  error: null,
93
85
  },
@@ -96,7 +88,6 @@ describe("authentication reducer", () => {
96
88
  }
97
89
  )
98
90
  ).toStrictEqual({
99
- isAuthenticated: true,
100
91
  mustChangePassword: true,
101
92
  error: null,
102
93
  });
@@ -168,7 +168,6 @@ export type ReduxAction =
168
168
 
169
169
  // Redux state
170
170
  export type AuthState = {
171
- +isAuthenticated: boolean,
172
171
  +mustChangePassword: boolean,
173
172
  +error: ?string,
174
173
  };
@@ -17,6 +17,8 @@ export const resourceExists = (url: string | Href): boolean => {
17
17
  xhr.open("HEAD", fullUrl, false);
18
18
  xhr.setRequestHeader("Accept", "application/json");
19
19
  xhr.setRequestHeader("Content-Type", "application/json");
20
+ xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
21
+
20
22
  xhr.send();
21
23
 
22
24
  return xhr.status !== 404;
@@ -34,6 +36,7 @@ export const resourceRedirectsToSecureLogin = (url: string | Href): boolean => {
34
36
  xhr.open("HEAD", fullUrl, false);
35
37
  xhr.setRequestHeader("Accept", "application/json");
36
38
  xhr.setRequestHeader("Content-Type", "application/json");
39
+ xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
37
40
  xhr.send();
38
41
 
39
42
  const responseURL = xhr.responseURL ?? "";