@lobb-js/lobb-ext-auth 0.6.0 → 0.7.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/dist/onStartup.js +6 -0
- package/extensions/auth/collections/collections.ts +10 -0
- package/extensions/auth/collections/users.ts +3 -2
- package/extensions/auth/config/extensionConfigSchema.ts +3 -0
- package/extensions/auth/meta/meta.ts +1 -0
- package/extensions/auth/studio/onStartup.ts +8 -0
- package/extensions/auth/tests/middlewares/publicPreventBasic.test.ts +4 -4
- package/extensions/auth/workflows/utils.ts +6 -0
- package/package.json +2 -2
package/dist/onStartup.js
CHANGED
|
@@ -17,5 +17,11 @@ export async function onStartup(utils) {
|
|
|
17
17
|
utils.ctx.extensions.auth.session = session;
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
|
+
// Allow public paths without login
|
|
21
|
+
const publicPaths = utils.ctx.meta?.extensions?.auth?.studio?.publicPaths ?? [];
|
|
22
|
+
const currentPath = window.location.pathname;
|
|
23
|
+
if (publicPaths.some(p => currentPath.startsWith(p))) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
20
26
|
await auth.logout();
|
|
21
27
|
}
|
|
@@ -12,6 +12,16 @@ export function collections(
|
|
|
12
12
|
collectionsSchemas["auth_users"] = usersCollection;
|
|
13
13
|
collectionsSchemas["auth_sessions"] = sessionsCollection;
|
|
14
14
|
|
|
15
|
+
// Convert the role field to an enum based on configured roles
|
|
16
|
+
const roleNames = Object.keys(extensionConfig.roles ?? {}).filter(r => r !== "public");
|
|
17
|
+
if (roleNames.length > 0) {
|
|
18
|
+
const usersFields = (collectionsSchemas["auth_users"] as { fields: Record<string, any> }).fields;
|
|
19
|
+
usersFields.role = {
|
|
20
|
+
...usersFields.role,
|
|
21
|
+
enum: [{ value: "admin" }, ...roleNames.map(r => ({ value: r }))],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
15
25
|
// adding the additional fields and indexes if the extend_users property exists
|
|
16
26
|
if (extensionConfig.extend_users) {
|
|
17
27
|
collectionsSchemas["auth_users"].indexes = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { NormalCollectionConfig } from "@lobb-js/core";
|
|
2
2
|
import { hash } from "argon2";
|
|
3
3
|
|
|
4
|
-
export const usersCollection:
|
|
4
|
+
export const usersCollection: NormalCollectionConfig = {
|
|
5
5
|
indexes: {
|
|
6
6
|
auth_users_email_index: {
|
|
7
7
|
unique: true,
|
|
@@ -39,6 +39,7 @@ export const usersCollection: CollectionConfig = {
|
|
|
39
39
|
type: "string",
|
|
40
40
|
length: 255,
|
|
41
41
|
required: true,
|
|
42
|
+
enum: []
|
|
42
43
|
},
|
|
43
44
|
},
|
|
44
45
|
};
|
|
@@ -6,6 +6,7 @@ export async function meta(lobb: Lobb, extensionConfig: ExtensionConfig) {
|
|
|
6
6
|
const meta: any = {};
|
|
7
7
|
|
|
8
8
|
meta["dashboard_access_roles"] = config.dashboard_access_roles ?? ["admin"];
|
|
9
|
+
meta["studio"] = { publicPaths: config.studio?.publicPaths ?? [] };
|
|
9
10
|
|
|
10
11
|
return meta;
|
|
11
12
|
}
|
|
@@ -21,5 +21,13 @@ export async function onStartup(utils: ExtensionUtils) {
|
|
|
21
21
|
utils.ctx.extensions.auth.session = session;
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
+
|
|
25
|
+
// Allow public paths without login
|
|
26
|
+
const publicPaths: string[] = utils.ctx.meta?.extensions?.auth?.studio?.publicPaths ?? [];
|
|
27
|
+
const currentPath = window.location.pathname;
|
|
28
|
+
if (publicPaths.some(p => currentPath.startsWith(p))) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
24
32
|
await auth.logout()
|
|
25
33
|
}
|
|
@@ -38,7 +38,7 @@ describe("Prevent Guard For Public Users", () => {
|
|
|
38
38
|
|
|
39
39
|
expect(
|
|
40
40
|
result.message,
|
|
41
|
-
).toEqual("
|
|
41
|
+
).toEqual("You do not have permission to perform this action.");
|
|
42
42
|
expect(response.status).toEqual(403);
|
|
43
43
|
});
|
|
44
44
|
|
|
@@ -54,7 +54,7 @@ describe("Prevent Guard For Public Users", () => {
|
|
|
54
54
|
|
|
55
55
|
expect(
|
|
56
56
|
result.message,
|
|
57
|
-
).toEqual("
|
|
57
|
+
).toEqual("You do not have permission to perform this action.");
|
|
58
58
|
expect(response.status).toEqual(403);
|
|
59
59
|
});
|
|
60
60
|
|
|
@@ -81,7 +81,7 @@ describe("Prevent Guard For Public Users", () => {
|
|
|
81
81
|
).toEqual({
|
|
82
82
|
status: 403,
|
|
83
83
|
code: "FORBIDDEN",
|
|
84
|
-
message: "
|
|
84
|
+
message: "You do not have permission to perform this action.",
|
|
85
85
|
});
|
|
86
86
|
expect(response.status).toEqual(403);
|
|
87
87
|
});
|
|
@@ -100,7 +100,7 @@ describe("Prevent Guard For Public Users", () => {
|
|
|
100
100
|
result,
|
|
101
101
|
).toEqual({
|
|
102
102
|
code: "FORBIDDEN",
|
|
103
|
-
message: "
|
|
103
|
+
message: "You do not have permission to perform this action.",
|
|
104
104
|
status: 403,
|
|
105
105
|
});
|
|
106
106
|
expect(response.status).toEqual(403);
|
|
@@ -40,6 +40,12 @@ export function handlePolicy({
|
|
|
40
40
|
const currentRole = config.roles?.[role];
|
|
41
41
|
|
|
42
42
|
if (typeof currentRole === "undefined") {
|
|
43
|
+
if (role === "public") {
|
|
44
|
+
throw new ctx.LobbError({
|
|
45
|
+
code: "FORBIDDEN",
|
|
46
|
+
message: "You do not have permission to perform this action.",
|
|
47
|
+
});
|
|
48
|
+
}
|
|
43
49
|
throw new ctx.LobbError({
|
|
44
50
|
code: "FORBIDDEN",
|
|
45
51
|
message: "Your role is not recognized by the system.",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobb-js/lobb-ext-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"package": "svelte-package --input extensions/auth/studio"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@lobb-js/core": "^0.
|
|
36
|
+
"@lobb-js/core": "^0.27.0",
|
|
37
37
|
"argon2": "^0.40.3",
|
|
38
38
|
"hono": "^4.7.0"
|
|
39
39
|
},
|