@lobb-js/lobb-ext-auth 0.1.58
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/.zed/settings.json +22 -0
- package/deno.json +18 -0
- package/deno.lock +968 -0
- package/lobb/lobb.ts +108 -0
- package/lobb/src/collections/activityFeed.ts +53 -0
- package/lobb/src/collections/collections.ts +44 -0
- package/lobb/src/collections/sessions.ts +34 -0
- package/lobb/src/collections/users.ts +44 -0
- package/lobb/src/config/config.ts +11 -0
- package/lobb/src/config/extensionConfigSchema.ts +47 -0
- package/lobb/src/config/permissionsAction/create.ts +20 -0
- package/lobb/src/config/permissionsAction/delete.ts +3 -0
- package/lobb/src/config/permissionsAction/read.ts +10 -0
- package/lobb/src/config/permissionsAction/update.ts +20 -0
- package/lobb/src/database/init.ts +51 -0
- package/lobb/src/database/migrations.ts +56 -0
- package/lobb/src/database/utils.ts +35 -0
- package/lobb/src/extension.json +1 -0
- package/lobb/src/meta/meta.ts +11 -0
- package/lobb/src/mod.ts +27 -0
- package/lobb/src/openapi.ts +469 -0
- package/lobb/src/utils.ts +17 -0
- package/lobb/src/workflows/baseWorkflow.ts +159 -0
- package/lobb/src/workflows/hashHandlerWorkflows.ts +29 -0
- package/lobb/src/workflows/index.ts +28 -0
- package/lobb/src/workflows/meAliasWorkflows.ts +48 -0
- package/lobb/src/workflows/policiesWorkflows.ts +228 -0
- package/lobb/src/workflows/utils.ts +297 -0
- package/lobb/tests/collections/extend_users_collection.test.ts +63 -0
- package/lobb/tests/configs/auth.ts +72 -0
- package/lobb/tests/configs/auth_no_roles.ts +64 -0
- package/lobb/tests/configs/auth_public_full_access.ts +68 -0
- package/lobb/tests/configs/auth_with_different_admin_creds.ts +80 -0
- package/lobb/tests/configs/auth_with_extend_users.ts +80 -0
- package/lobb/tests/configs/auth_with_refresh_token.ts +85 -0
- package/lobb/tests/configs/auth_with_short_access_token_only.ts +94 -0
- package/lobb/tests/configs/auth_with_short_time_refresh_token.ts +85 -0
- package/lobb/tests/configs/social_blog.ts +155 -0
- package/lobb/tests/controllers/change_password.test.ts +114 -0
- package/lobb/tests/controllers/dashboardAccessRoles.test.ts +29 -0
- package/lobb/tests/controllers/login.test.ts +103 -0
- package/lobb/tests/controllers/logout.test.ts +88 -0
- package/lobb/tests/controllers/me.test.ts +275 -0
- package/lobb/tests/controllers/register.test.ts +46 -0
- package/lobb/tests/database/db.test.ts +68 -0
- package/lobb/tests/database/differentAdminCreds.test.ts +50 -0
- package/lobb/tests/middlewares/adminAuthGuard.test.ts +160 -0
- package/lobb/tests/middlewares/publicAllowBasic.test.ts +142 -0
- package/lobb/tests/middlewares/publicPreventBasic.test.ts +111 -0
- package/lobb/tests/socialBlog.test.ts +260 -0
- package/lobb/tests/utils/addArticles.ts +26 -0
- package/lobb/tests/utils/addSocialBlogArticles.ts +60 -0
- package/lobb/tests/utils/data/articles.ts +65 -0
- package/lobb/tests/utils/data/socialBlogArticles.ts +56 -0
- package/package.json +32 -0
- package/studio/.env +1 -0
- package/studio/README.md +1 -0
- package/studio/index.html +13 -0
- package/studio/postcss.config.js +6 -0
- package/studio/public/vite.svg +1 -0
- package/studio/src/auth.ts +57 -0
- package/studio/src/index.ts +54 -0
- package/studio/src/main.ts +12 -0
- package/studio/src/onStartup.ts +25 -0
- package/studio/src/pages/loginPage/index.svelte +64 -0
- package/studio/src/pages/settings/index.svelte +53 -0
- package/studio/src/pages/settings/pages/activityFeed.svelte +21 -0
- package/studio/src/pages/settings/pages/rolesAndPermissions.svelte +21 -0
- package/studio/src/pages/settings/pages/users.svelte +21 -0
- package/studio/src/pages/userSettings/components/account.svelte +106 -0
- package/studio/src/pages/userSettings/components/profile.svelte +87 -0
- package/studio/src/pages/userSettings/index.svelte +48 -0
- package/studio/svelte.config.js +8 -0
- package/studio/tailwind.config.ts +93 -0
- package/studio/tsconfig.app.json +22 -0
- package/studio/tsconfig.json +7 -0
- package/studio/tsconfig.node.json +26 -0
- package/studio/vite.config.ts +14 -0
- package/todo.md +37 -0
package/lobb/lobb.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Lobb } from "@lobb/core";
|
|
2
|
+
import { auth } from "./src/mod.ts";
|
|
3
|
+
|
|
4
|
+
Lobb.init({
|
|
5
|
+
project: {
|
|
6
|
+
name: "Social To Courier",
|
|
7
|
+
force_sync: true,
|
|
8
|
+
},
|
|
9
|
+
database: {
|
|
10
|
+
host: "localhost",
|
|
11
|
+
port: 5432,
|
|
12
|
+
username: "test",
|
|
13
|
+
password: "test",
|
|
14
|
+
database: "social_to_courier",
|
|
15
|
+
},
|
|
16
|
+
web_server: {
|
|
17
|
+
host: "0.0.0.0",
|
|
18
|
+
port: 3000,
|
|
19
|
+
cors: {
|
|
20
|
+
origin: "*",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
extensions: [
|
|
24
|
+
auth({
|
|
25
|
+
admin: {
|
|
26
|
+
email: "admin@example.com",
|
|
27
|
+
password: "admin",
|
|
28
|
+
},
|
|
29
|
+
extend_users: {
|
|
30
|
+
fields: {
|
|
31
|
+
instagram_user_id: {
|
|
32
|
+
type: "string",
|
|
33
|
+
length: 255,
|
|
34
|
+
},
|
|
35
|
+
instagram_token: {
|
|
36
|
+
type: "string",
|
|
37
|
+
length: 255,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
roles: {
|
|
42
|
+
public: {
|
|
43
|
+
permissions: true,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
}),
|
|
47
|
+
],
|
|
48
|
+
collections: {
|
|
49
|
+
articles: {
|
|
50
|
+
indexes: {},
|
|
51
|
+
fields: {
|
|
52
|
+
id: {
|
|
53
|
+
type: "integer",
|
|
54
|
+
},
|
|
55
|
+
image: {
|
|
56
|
+
type: "string",
|
|
57
|
+
length: 255,
|
|
58
|
+
},
|
|
59
|
+
title: {
|
|
60
|
+
type: "string",
|
|
61
|
+
length: 255,
|
|
62
|
+
validators: {
|
|
63
|
+
required: true,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
description: {
|
|
67
|
+
type: "string",
|
|
68
|
+
length: 255,
|
|
69
|
+
},
|
|
70
|
+
body: {
|
|
71
|
+
type: "string",
|
|
72
|
+
length: 255,
|
|
73
|
+
validators: {
|
|
74
|
+
required: true,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
status: {
|
|
78
|
+
type: "string",
|
|
79
|
+
length: 255,
|
|
80
|
+
validators: {
|
|
81
|
+
enum: ["public", "private"],
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
comments: {
|
|
87
|
+
indexes: {},
|
|
88
|
+
fields: {
|
|
89
|
+
id: {
|
|
90
|
+
type: "integer",
|
|
91
|
+
},
|
|
92
|
+
body: {
|
|
93
|
+
type: "string",
|
|
94
|
+
length: 255,
|
|
95
|
+
validators: {
|
|
96
|
+
required: true,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
article_id: {
|
|
100
|
+
type: "integer",
|
|
101
|
+
validators: {
|
|
102
|
+
required: true,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { CollectionConfig } from "@lobb/core/types";
|
|
2
|
+
|
|
3
|
+
export const activityFeedCollection: CollectionConfig = {
|
|
4
|
+
indexes: {},
|
|
5
|
+
fields: {
|
|
6
|
+
id: {
|
|
7
|
+
type: "integer",
|
|
8
|
+
},
|
|
9
|
+
user_id: {
|
|
10
|
+
type: "integer",
|
|
11
|
+
references: {
|
|
12
|
+
collection: "auth_users",
|
|
13
|
+
field: "id",
|
|
14
|
+
},
|
|
15
|
+
validators: {
|
|
16
|
+
required: true,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
action: {
|
|
20
|
+
type: "string",
|
|
21
|
+
length: 255,
|
|
22
|
+
validators: {
|
|
23
|
+
required: true,
|
|
24
|
+
enum: [
|
|
25
|
+
"create",
|
|
26
|
+
"read",
|
|
27
|
+
"update",
|
|
28
|
+
"delete",
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
collection: {
|
|
33
|
+
type: "string",
|
|
34
|
+
length: 255,
|
|
35
|
+
validators: {
|
|
36
|
+
required: true,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
item_id: {
|
|
40
|
+
type: "string",
|
|
41
|
+
length: 255,
|
|
42
|
+
validators: {
|
|
43
|
+
required: true,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
created_at: {
|
|
47
|
+
type: "datetime",
|
|
48
|
+
pre_processors: {
|
|
49
|
+
default: "{{ now }}",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { CollectionConfig, Lobb } from "@lobb/core/types";
|
|
2
|
+
import { usersCollection } from "./users.ts";
|
|
3
|
+
import { sessionsCollection } from "./sessions.ts";
|
|
4
|
+
import { getExtensionConfig } from "../config/config.ts";
|
|
5
|
+
import { activityFeedCollection } from "./activityFeed.ts";
|
|
6
|
+
|
|
7
|
+
export function collections(
|
|
8
|
+
lobb: Lobb,
|
|
9
|
+
): Record<string, CollectionConfig> {
|
|
10
|
+
const collectionsSchemas: Record<string, CollectionConfig> = {};
|
|
11
|
+
collectionsSchemas["auth_users"] = usersCollection;
|
|
12
|
+
collectionsSchemas["auth_sessions"] = sessionsCollection;
|
|
13
|
+
|
|
14
|
+
// adding the additional fields and indexes if the extend_users property exists
|
|
15
|
+
const extensionConfig = getExtensionConfig();
|
|
16
|
+
|
|
17
|
+
if (extensionConfig.extend_users) {
|
|
18
|
+
collectionsSchemas["auth_users"].indexes = {
|
|
19
|
+
...collectionsSchemas["auth_users"].indexes,
|
|
20
|
+
...extensionConfig.extend_users.indexes,
|
|
21
|
+
};
|
|
22
|
+
collectionsSchemas["auth_users"].fields = {
|
|
23
|
+
...collectionsSchemas["auth_users"].fields,
|
|
24
|
+
...extensionConfig.extend_users.fields,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const authConfig = getExtensionConfig();
|
|
29
|
+
|
|
30
|
+
if (!authConfig.roles) {
|
|
31
|
+
authConfig.roles = {};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
collectionsSchemas["auth_roles"] = lobb.utils.lockCollectionToObject(
|
|
35
|
+
{
|
|
36
|
+
collectionName: "auth_roles",
|
|
37
|
+
object: authConfig.roles,
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
collectionsSchemas["auth_activity_feed"] = activityFeedCollection;
|
|
42
|
+
|
|
43
|
+
return collectionsSchemas;
|
|
44
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { CollectionConfig } from "@lobb/core/types";
|
|
2
|
+
|
|
3
|
+
export const sessionsCollection: CollectionConfig = {
|
|
4
|
+
indexes: {},
|
|
5
|
+
fields: {
|
|
6
|
+
id: {
|
|
7
|
+
type: "integer",
|
|
8
|
+
},
|
|
9
|
+
user_id: {
|
|
10
|
+
type: "integer",
|
|
11
|
+
references: {
|
|
12
|
+
collection: "auth_users",
|
|
13
|
+
field: "id",
|
|
14
|
+
},
|
|
15
|
+
validators: {
|
|
16
|
+
required: true,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
token: {
|
|
20
|
+
type: "string",
|
|
21
|
+
length: 255,
|
|
22
|
+
validators: {
|
|
23
|
+
maxLength: 255,
|
|
24
|
+
required: true,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
expires_at: {
|
|
28
|
+
type: "datetime",
|
|
29
|
+
validators: {
|
|
30
|
+
required: true,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { CollectionConfig } from "@lobb/core/types";
|
|
2
|
+
|
|
3
|
+
export const usersCollection: CollectionConfig = {
|
|
4
|
+
indexes: {
|
|
5
|
+
auth_users_email_index: {
|
|
6
|
+
unique: true,
|
|
7
|
+
fields: {
|
|
8
|
+
email: {
|
|
9
|
+
order: "asc",
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
fields: {
|
|
15
|
+
id: {
|
|
16
|
+
type: "integer",
|
|
17
|
+
},
|
|
18
|
+
email: {
|
|
19
|
+
type: "string",
|
|
20
|
+
length: 255,
|
|
21
|
+
validators: {
|
|
22
|
+
validator: {
|
|
23
|
+
name: "isEmail",
|
|
24
|
+
},
|
|
25
|
+
maxLength: 255,
|
|
26
|
+
required: true,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
password: {
|
|
30
|
+
type: "string",
|
|
31
|
+
length: 255,
|
|
32
|
+
validators: {
|
|
33
|
+
required: true,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
role: {
|
|
37
|
+
type: "string",
|
|
38
|
+
length: 255,
|
|
39
|
+
validators: {
|
|
40
|
+
required: true,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ExtensionConfig } from "./extensionConfigSchema.ts";
|
|
2
|
+
|
|
3
|
+
let extensionConfig: ExtensionConfig;
|
|
4
|
+
|
|
5
|
+
export function setExtensionConfig(config: ExtensionConfig) {
|
|
6
|
+
extensionConfig = config;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function getExtensionConfig() {
|
|
10
|
+
return extensionConfig;
|
|
11
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { CollectionConfig } from "@lobb/core/types";
|
|
2
|
+
import type { CreatePermissionAction } from "./permissionsAction/create.ts";
|
|
3
|
+
import type { ReadPermissionAction } from "./permissionsAction/read.ts";
|
|
4
|
+
import type { UpdatePermissionAction } from "./permissionsAction/update.ts";
|
|
5
|
+
import type { DeletePermissionAction } from "./permissionsAction/delete.ts";
|
|
6
|
+
|
|
7
|
+
export interface User {
|
|
8
|
+
id: number;
|
|
9
|
+
email: string;
|
|
10
|
+
password: string;
|
|
11
|
+
role: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface PermissionAction {}
|
|
15
|
+
|
|
16
|
+
export type CollectionPermissionsActions = {
|
|
17
|
+
create?: true | CreatePermissionAction;
|
|
18
|
+
read?: true | ReadPermissionAction;
|
|
19
|
+
update?: true | UpdatePermissionAction;
|
|
20
|
+
delete?: true | DeletePermissionAction;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type CollectionPermissionActionsKeys =
|
|
24
|
+
keyof CollectionPermissionsActions;
|
|
25
|
+
export type CollectionPermissionsConfig =
|
|
26
|
+
| true
|
|
27
|
+
| CollectionPermissionsActions;
|
|
28
|
+
export type PermissionsConfig =
|
|
29
|
+
| true
|
|
30
|
+
| Record<string, CollectionPermissionsConfig | undefined>;
|
|
31
|
+
|
|
32
|
+
export type RolesConfig = {
|
|
33
|
+
permissions: PermissionsConfig;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type ExtensionConfig = {
|
|
37
|
+
admin: {
|
|
38
|
+
password: string;
|
|
39
|
+
email: string;
|
|
40
|
+
};
|
|
41
|
+
dashboard_access_roles?: string[];
|
|
42
|
+
roles: Record<string, RolesConfig | undefined>;
|
|
43
|
+
extend_users?: {
|
|
44
|
+
indexes?: CollectionConfig["indexes"];
|
|
45
|
+
fields?: Omit<CollectionConfig["fields"], "id">;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PermissionAction, User } from "../extensionConfigSchema.ts";
|
|
2
|
+
|
|
3
|
+
interface FieldTrasnsformerFnParams {
|
|
4
|
+
value: unknown;
|
|
5
|
+
payload: Record<string, unknown>;
|
|
6
|
+
user?: User;
|
|
7
|
+
}
|
|
8
|
+
type FieldTrasnsformerFn = (params: FieldTrasnsformerFnParams) => unknown;
|
|
9
|
+
|
|
10
|
+
interface CreateGuardProps {
|
|
11
|
+
payload: Record<string, unknown>;
|
|
12
|
+
user?: User;
|
|
13
|
+
}
|
|
14
|
+
type CreateGuardFn = (props: CreateGuardProps) => true | void;
|
|
15
|
+
|
|
16
|
+
export interface CreatePermissionAction extends PermissionAction {
|
|
17
|
+
payloadGuard?: CreateGuardFn;
|
|
18
|
+
fields?: Record<string, true>;
|
|
19
|
+
mutate?: Record<string, FieldTrasnsformerFn>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Filter } from "@lobb/core/types";
|
|
2
|
+
import type { PermissionAction, User } from "../extensionConfigSchema.ts";
|
|
3
|
+
|
|
4
|
+
export interface ReadPermissionAction extends PermissionAction {
|
|
5
|
+
/**
|
|
6
|
+
* Filter that gets passed to the db select query condition
|
|
7
|
+
*/
|
|
8
|
+
filter?: Filter<{ user?: User }>;
|
|
9
|
+
fields?: Record<string, true>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PermissionAction, User } from "../extensionConfigSchema.ts";
|
|
2
|
+
|
|
3
|
+
interface FieldTrasnsformerFnParams {
|
|
4
|
+
value: unknown;
|
|
5
|
+
payload: Record<string, unknown>;
|
|
6
|
+
user?: User;
|
|
7
|
+
}
|
|
8
|
+
type FieldTrasnsformerFn = (params: FieldTrasnsformerFnParams) => unknown;
|
|
9
|
+
|
|
10
|
+
interface UpdateGuardProps {
|
|
11
|
+
payload: Record<string, unknown>;
|
|
12
|
+
user?: User;
|
|
13
|
+
}
|
|
14
|
+
type UpdateGuardFn = (props: UpdateGuardProps) => true | void;
|
|
15
|
+
|
|
16
|
+
export interface UpdatePermissionAction extends PermissionAction {
|
|
17
|
+
payloadGuard?: UpdateGuardFn;
|
|
18
|
+
fields?: Record<string, true>;
|
|
19
|
+
mutate?: Record<string, FieldTrasnsformerFn>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { Lobb } from "@lobb/core/types";
|
|
2
|
+
import { verify } from "@bronti/argon2";
|
|
3
|
+
import { getExtensionConfig } from "../config/config.ts";
|
|
4
|
+
import { checkCollectionsInPermissions } from "./utils.ts";
|
|
5
|
+
|
|
6
|
+
export async function init(lobb: Lobb) {
|
|
7
|
+
checkCollectionsInPermissions(lobb);
|
|
8
|
+
await syncincAdminUserInDB(lobb);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async function syncincAdminUserInDB(lobb: Lobb) {
|
|
12
|
+
// syncinc the admin user in users collection
|
|
13
|
+
const config = getExtensionConfig();
|
|
14
|
+
const adminUserData = config.admin;
|
|
15
|
+
const users = lobb.utils.getCollectionService({
|
|
16
|
+
collectionName: "auth_users",
|
|
17
|
+
});
|
|
18
|
+
const entries = (await users.findAll({
|
|
19
|
+
params: {
|
|
20
|
+
filter: {
|
|
21
|
+
role: "admin",
|
|
22
|
+
},
|
|
23
|
+
sort: "id",
|
|
24
|
+
},
|
|
25
|
+
})).data;
|
|
26
|
+
const adminUser = entries[0];
|
|
27
|
+
if (!adminUser) {
|
|
28
|
+
await users.createOne({
|
|
29
|
+
data: {
|
|
30
|
+
email: adminUserData.email,
|
|
31
|
+
password: adminUserData.password,
|
|
32
|
+
role: "admin",
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
} else {
|
|
36
|
+
const passwordIdentical = await verify(
|
|
37
|
+
adminUserData.password,
|
|
38
|
+
adminUser.password,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
if (adminUser.email !== adminUserData.email || !passwordIdentical) {
|
|
42
|
+
await users.updateOne({
|
|
43
|
+
id: adminUser.id,
|
|
44
|
+
data: {
|
|
45
|
+
email: adminUserData.email,
|
|
46
|
+
password: adminUserData.password,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Migrations } from "@lobb/core/types";
|
|
2
|
+
|
|
3
|
+
export const migrations: Migrations = {
|
|
4
|
+
"create_users_collections": {
|
|
5
|
+
async up(props) {
|
|
6
|
+
await props.driver.createCollection("auth_users", {
|
|
7
|
+
"indexes": {
|
|
8
|
+
"email_index": {
|
|
9
|
+
"unique": true,
|
|
10
|
+
"fields": {
|
|
11
|
+
"email": {
|
|
12
|
+
"order": "asc",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
"fields": {
|
|
18
|
+
"id": {
|
|
19
|
+
"type": "integer",
|
|
20
|
+
},
|
|
21
|
+
"email": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"length": 255,
|
|
24
|
+
"validators": {
|
|
25
|
+
"required": true,
|
|
26
|
+
"validator": {
|
|
27
|
+
"name": "isEmail",
|
|
28
|
+
},
|
|
29
|
+
"maxLength": 255,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
"password": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"length": 255,
|
|
35
|
+
"validators": {
|
|
36
|
+
"required": true,
|
|
37
|
+
},
|
|
38
|
+
"pre_processors": {
|
|
39
|
+
"hash": true,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
"role": {
|
|
43
|
+
"type": "string",
|
|
44
|
+
"length": 255,
|
|
45
|
+
"validators": {
|
|
46
|
+
"required": true,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
async down(props) {
|
|
53
|
+
await props.driver.dropCollection("auth_users");
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Lobb } from "@lobb/core/types";
|
|
2
|
+
import { LobbError } from "@lobb/core";
|
|
3
|
+
import { getExtensionConfig } from "../config/config.ts";
|
|
4
|
+
|
|
5
|
+
export function checkCollectionsInPermissions(
|
|
6
|
+
lobb: Lobb,
|
|
7
|
+
) {
|
|
8
|
+
const authExtensionConfig = getExtensionConfig();
|
|
9
|
+
for (const roleName in authExtensionConfig.roles) {
|
|
10
|
+
const role = authExtensionConfig.roles[roleName];
|
|
11
|
+
|
|
12
|
+
if (typeof role === "undefined") {
|
|
13
|
+
throw new LobbError({
|
|
14
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
15
|
+
message: `The (${roleName}) role in the auth permissions doesnt exist`,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const permissions = role.permissions;
|
|
20
|
+
const collectionNames = Object.keys(permissions);
|
|
21
|
+
for (let index = 0; index < collectionNames.length; index++) {
|
|
22
|
+
const collectionName = collectionNames[index];
|
|
23
|
+
const collectionExists = lobb.configManager.collectionExists(
|
|
24
|
+
collectionName,
|
|
25
|
+
);
|
|
26
|
+
if (!collectionExists) {
|
|
27
|
+
throw new LobbError({
|
|
28
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
29
|
+
message:
|
|
30
|
+
`The (${collectionName}) collection in the auth permissions doesnt exist`,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Lobb } from "@lobb/core/types";
|
|
2
|
+
import { getExtensionConfig } from "../config/config.ts";
|
|
3
|
+
|
|
4
|
+
export async function meta(lobb: Lobb) {
|
|
5
|
+
const config = getExtensionConfig();
|
|
6
|
+
const meta: any = {};
|
|
7
|
+
|
|
8
|
+
meta["dashboard_access_roles"] = config.dashboard_access_roles ?? ["admin"];
|
|
9
|
+
|
|
10
|
+
return meta;
|
|
11
|
+
}
|
package/lobb/src/mod.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Extension } from "@lobb/core/types";
|
|
2
|
+
import type { ExtensionConfig } from "./config/extensionConfigSchema.ts";
|
|
3
|
+
|
|
4
|
+
import denoJson from "../../deno.json" with { type: "json" };
|
|
5
|
+
import extension from "./extension.json" with { type: "json" };
|
|
6
|
+
import { init } from "./database/init.ts";
|
|
7
|
+
import { collections } from "./collections/collections.ts";
|
|
8
|
+
import { meta } from "./meta/meta.ts";
|
|
9
|
+
import { migrations } from "./database/migrations.ts";
|
|
10
|
+
import { setExtensionConfig } from "./config/config.ts";
|
|
11
|
+
import { getWorkflows } from "./workflows/index.ts";
|
|
12
|
+
// import { openapi } from "./openapi.ts";
|
|
13
|
+
|
|
14
|
+
export function auth(extensionConfig: ExtensionConfig): Extension {
|
|
15
|
+
setExtensionConfig(extensionConfig);
|
|
16
|
+
return {
|
|
17
|
+
version: denoJson.version,
|
|
18
|
+
name: "auth",
|
|
19
|
+
init: init,
|
|
20
|
+
collections: collections,
|
|
21
|
+
migrations: migrations,
|
|
22
|
+
meta: meta,
|
|
23
|
+
workflows: getWorkflows(),
|
|
24
|
+
dashboard: extension,
|
|
25
|
+
// openapi: openapi,
|
|
26
|
+
};
|
|
27
|
+
}
|