@pronto-tools-and-more/network-process 3.16.0 → 4.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.
- package/package.json +1 -1
- package/src/parts/Login/Login.js +19 -14
package/package.json
CHANGED
package/src/parts/Login/Login.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
import { VError } from "@lvce-editor/verror";
|
|
2
2
|
import ky from "ky";
|
|
3
3
|
import * as Assert from "../Assert/Assert.js";
|
|
4
|
-
import * as GetXr from "../GetXr/GetXr.js";
|
|
5
4
|
|
|
6
|
-
const
|
|
5
|
+
const getBodyFormData = (userEmail, userPassword) => {
|
|
7
6
|
Assert.string(userEmail);
|
|
8
7
|
Assert.string(userPassword);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
const formData = new URLSearchParams();
|
|
9
|
+
formData.set("client_id", "experience-builder");
|
|
10
|
+
formData.set("grant_type", "password");
|
|
11
|
+
formData.set("scope", "openid");
|
|
12
|
+
formData.set("username", userEmail);
|
|
13
|
+
formData.set("password", userPassword);
|
|
14
|
+
return formData;
|
|
14
15
|
};
|
|
15
16
|
|
|
16
17
|
const getHeaders = () => {
|
|
17
|
-
const xr = GetXr.getXr();
|
|
18
18
|
return {
|
|
19
|
-
|
|
20
|
-
"content-type": "application/json",
|
|
21
|
-
xr,
|
|
19
|
+
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
|
|
22
20
|
};
|
|
23
21
|
};
|
|
24
22
|
|
|
@@ -30,19 +28,26 @@ const getHeaders = () => {
|
|
|
30
28
|
export const login = async ({ loginUrl, userEmail, userPassword }) => {
|
|
31
29
|
try {
|
|
32
30
|
Assert.string(loginUrl);
|
|
33
|
-
const body =
|
|
31
|
+
const body = getBodyFormData(userEmail, userPassword);
|
|
34
32
|
const headers = getHeaders();
|
|
35
33
|
const response = await ky(loginUrl, {
|
|
36
|
-
|
|
34
|
+
body,
|
|
37
35
|
method: "post",
|
|
38
36
|
headers,
|
|
39
37
|
});
|
|
40
|
-
|
|
38
|
+
const result = await response.json();
|
|
39
|
+
console.log({ result });
|
|
40
|
+
return result;
|
|
41
41
|
} catch (error) {
|
|
42
42
|
// @ts-ignore
|
|
43
43
|
if (error && error.name === "HTTPError") {
|
|
44
44
|
// @ts-ignore
|
|
45
45
|
const serverMessage = await error.response.text();
|
|
46
|
+
if (serverMessage.includes("Cannot POST /api/user/login")) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`Failed to login: Unable to login due to breaking api changes in the backend (see https://purplepublish.atlassian.net/browse/BACKEND-5178)`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
46
51
|
if (serverMessage === "INTERNAL_ERROR") {
|
|
47
52
|
throw new Error("Failed to login: Internal error. Hint: Check headers");
|
|
48
53
|
}
|