@saltcorn/mobile-app 1.3.1-beta.11 → 1.3.1-beta.12
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 +2 -2
- package/src/helpers/auth.js +29 -18
- package/src/helpers/offline_mode.js +3 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saltcorn/mobile-app",
|
|
3
3
|
"displayName": "Saltcorn mobile app",
|
|
4
|
-
"version": "1.3.1-beta.
|
|
4
|
+
"version": "1.3.1-beta.12",
|
|
5
5
|
"description": "Saltcorn mobile app for Android and iOS",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"scripts": {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"universal-router": "9.2.1",
|
|
21
|
-
"axios": "^
|
|
21
|
+
"axios": "^0.29.0",
|
|
22
22
|
"jwt-decode": "4.0.0",
|
|
23
23
|
"i18next": "24.2.2",
|
|
24
24
|
"i18next-sprintf-postprocessor": "0.2.2",
|
package/src/helpers/auth.js
CHANGED
|
@@ -19,27 +19,27 @@ async function loginRequest({ email, password, isSignup, isPublic }) {
|
|
|
19
19
|
path: "/auth/login-with/jwt",
|
|
20
20
|
}
|
|
21
21
|
: isSignup
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
22
|
+
? {
|
|
23
|
+
method: "POST",
|
|
24
|
+
path: "/auth/signup",
|
|
25
|
+
body: {
|
|
26
|
+
email,
|
|
27
|
+
password,
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
: {
|
|
31
|
+
method: "GET",
|
|
32
|
+
path: "/auth/login-with/jwt",
|
|
33
|
+
params: {
|
|
34
|
+
email,
|
|
35
|
+
password,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
38
|
const response = await apiCall(opts);
|
|
39
39
|
return response.data;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export async function login({ email, password,
|
|
42
|
+
export async function login({ email, password, isSignup }) {
|
|
43
43
|
const loginResult = await loginRequest({
|
|
44
44
|
email,
|
|
45
45
|
password,
|
|
@@ -48,7 +48,8 @@ export async function login({ email, password, entryPoint, isSignup }) {
|
|
|
48
48
|
if (typeof loginResult === "string") {
|
|
49
49
|
// use it as a token
|
|
50
50
|
const decodedJwt = jwtDecode(loginResult);
|
|
51
|
-
const
|
|
51
|
+
const state = saltcorn.data.state.getState();
|
|
52
|
+
const config = state.mobileConfig;
|
|
52
53
|
config.user = decodedJwt.user;
|
|
53
54
|
config.isPublicUser = false;
|
|
54
55
|
config.isOfflineMode = false;
|
|
@@ -86,6 +87,16 @@ export async function login({ email, password, entryPoint, isSignup }) {
|
|
|
86
87
|
sprintf: [config.user.email],
|
|
87
88
|
}),
|
|
88
89
|
});
|
|
90
|
+
|
|
91
|
+
let entryPoint = null;
|
|
92
|
+
if (config.entryPointType === "byrole") {
|
|
93
|
+
const homepageByRole = state.getConfig("home_page_by_role", {})[
|
|
94
|
+
config.user.role_id
|
|
95
|
+
];
|
|
96
|
+
if (homepageByRole) entryPoint = `get/page/${homepageByRole}`;
|
|
97
|
+
else throw new Error("No homepage defined for this role.");
|
|
98
|
+
} else entryPoint = config.entry_point;
|
|
99
|
+
|
|
89
100
|
addRoute({ route: entryPoint, query: undefined });
|
|
90
101
|
const page = await router.resolve({
|
|
91
102
|
pathname: entryPoint,
|
|
@@ -224,8 +224,8 @@ const loadOfflineChanges = async (synchedTbls) => {
|
|
|
224
224
|
from "${saltcorn.data.db.sqlsanitize(
|
|
225
225
|
synchedTbl
|
|
226
226
|
)}_sync_info" as info_tbl left join "${saltcorn.data.db.sqlsanitize(
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
synchedTbl
|
|
228
|
+
)}" as data_tbl
|
|
229
229
|
on info_tbl.ref = data_tbl."${saltcorn.data.db.sqlsanitize(pkName)}"
|
|
230
230
|
where info_tbl.modified_local = true`
|
|
231
231
|
);
|
|
@@ -562,7 +562,7 @@ export async function clearLocalData(inTransaction) {
|
|
|
562
562
|
const { synchedTables } = saltcorn.data.state.getState().mobileConfig;
|
|
563
563
|
for (const tblName of synchedTables) {
|
|
564
564
|
const table = saltcorn.data.models.Table.findOne({ name: tblName });
|
|
565
|
-
await table.deleteRows();
|
|
565
|
+
await table.deleteRows({});
|
|
566
566
|
await saltcorn.data.db.deleteWhere(`${table.name}_sync_info`, {});
|
|
567
567
|
}
|
|
568
568
|
if (!inTransaction) await saltcorn.data.db.query("COMMIT");
|