zyket 1.2.11 → 1.2.13
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/.github/workflows/publish.yml +37 -37
- package/README.md +279 -279
- package/bin/cli.js +201 -201
- package/index.js +32 -32
- package/package.json +54 -50
- package/src/Middleware.js +3 -3
- package/src/extensions/Extension.js +10 -10
- package/src/extensions/bullboard/index.js +38 -38
- package/src/extensions/interactive-storage/index.js +162 -162
- package/src/extensions/interactive-storage/middlewares/MulterMiddleware.js +31 -31
- package/src/extensions/interactive-storage/routes/browse.js +31 -31
- package/src/extensions/interactive-storage/routes/create-folder.js +37 -37
- package/src/extensions/interactive-storage/routes/delete-folder.js +57 -57
- package/src/extensions/interactive-storage/routes/delete.js +41 -41
- package/src/extensions/interactive-storage/routes/download.js +47 -47
- package/src/extensions/interactive-storage/routes/info.js +37 -37
- package/src/extensions/interactive-storage/routes/upload.js +46 -46
- package/src/kernel/HTTPServer.js +31 -31
- package/src/kernel/index.js +78 -78
- package/src/services/Service.js +10 -10
- package/src/services/auth/auth.js +7 -7
- package/src/services/auth/index.js +199 -199
- package/src/services/bullmq/Worker.js +7 -7
- package/src/services/bullmq/index.js +92 -92
- package/src/services/cache/index.js +96 -96
- package/src/services/database/index.js +127 -127
- package/src/services/events/Event.js +6 -6
- package/src/services/events/index.js +59 -59
- package/src/services/express/Express.js +280 -248
- package/src/services/express/Middleware.js +7 -7
- package/src/services/express/RedirectResponse.js +8 -8
- package/src/services/express/Route.js +6 -6
- package/src/services/express/index.js +4 -4
- package/src/services/index.js +30 -29
- package/src/services/logger/index.js +84 -80
- package/src/services/s3/index.js +82 -82
- package/src/services/scheduler/Schedule.js +6 -6
- package/src/services/scheduler/index.js +47 -47
- package/src/services/socketio/Guard.js +10 -10
- package/src/services/socketio/Handler.js +10 -10
- package/src/services/socketio/SocketIO.js +159 -132
- package/src/services/socketio/index.js +4 -4
- package/src/services/template-manager/index.js +73 -73
- package/src/services/vite/builder.js +29 -0
- package/src/services/vite/index.js +23 -1
- package/src/templates/default/config/cors.js +4 -4
- package/src/templates/default/config/swagger.js +15 -15
- package/src/templates/default/frontend/main.jsx +15 -15
- package/src/templates/default/frontend/src/hooks/useAuth.jsx +51 -51
- package/src/templates/default/frontend/src/hooks/useLayout.jsx +18 -18
- package/src/templates/default/frontend/src/layouts/auth/index.jsx +45 -45
- package/src/templates/default/frontend/src/layouts/auth/routes.js +17 -17
- package/src/templates/default/frontend/src/layouts/landing/index.jsx +61 -61
- package/src/templates/default/frontend/src/layouts/landing/routes.js +10 -10
- package/src/templates/default/frontend/src/layouts/panel/index.jsx +115 -115
- package/src/templates/default/frontend/src/layouts/panel/routes.js +10 -10
- package/src/templates/default/frontend/src/middlewares/LoggedMiddleware.jsx +21 -21
- package/src/templates/default/frontend/src/middlewares/NotLoggedMiddleware.jsx +14 -14
- package/src/templates/default/frontend/src/store/index.jsx +5 -5
- package/src/templates/default/frontend/src/store/storeAuth.jsx +14 -14
- package/src/templates/default/frontend/src/views/auth/index.jsx +4 -4
- package/src/templates/default/frontend/src/views/auth/register/index.jsx +4 -4
- package/src/templates/default/frontend/src/views/landing/index.jsx +4 -4
- package/src/templates/default/frontend/src/views/panel/dashboard/index.jsx +4 -4
- package/src/templates/default/frontend/styles.css +1 -1
- package/src/templates/default/src/guards/default.js +6 -6
- package/src/templates/default/src/handlers/connection.js +6 -6
- package/src/templates/default/src/handlers/message.js +8 -8
- package/src/templates/default/src/middlewares/default.js +7 -7
- package/src/templates/default/src/routes/[test]/message.js +26 -26
- package/src/templates/default/src/routes/index.js +22 -22
- package/src/templates/default/src/services/auth/auth.js +7 -7
- package/src/templates/default/src/services/auth/index.js +32 -32
- package/src/utils/EnvManager.js +66 -65
package/src/kernel/index.js
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
const {ContainerBuilder} = require("node-dependency-injection");
|
|
2
|
-
const EnvManager = require("../utils/EnvManager");
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const HTTPServer = require("./HTTPServer");
|
|
6
|
-
const Extension = require("../extensions/Extension");
|
|
7
|
-
|
|
8
|
-
module.exports = class Kernel {
|
|
9
|
-
container;
|
|
10
|
-
#services;
|
|
11
|
-
#onSocketConnection;
|
|
12
|
-
#httpServer;
|
|
13
|
-
#extensions = [];
|
|
14
|
-
|
|
15
|
-
constructor({
|
|
16
|
-
services = [],
|
|
17
|
-
extensions = [],
|
|
18
|
-
} = { }) {
|
|
19
|
-
this.container = new ContainerBuilder();
|
|
20
|
-
this.#services = services;
|
|
21
|
-
this.#extensions = extensions;
|
|
22
|
-
|
|
23
|
-
// create src folder if not exists
|
|
24
|
-
if (!fs.existsSync(path.join(process.cwd(), "src"))) {
|
|
25
|
-
fs.mkdirSync(path.join(process.cwd(), "src"));
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async boot(clearConsole = true, secretsPath = `${process.cwd()}/.env`) {
|
|
30
|
-
EnvManager.load(secretsPath, false);
|
|
31
|
-
if(clearConsole) process.stdout.write("\u001b[2J\u001b[0;0H");
|
|
32
|
-
this.#httpServer = new HTTPServer({ port: Number(process.env.PORT) || 3000 });
|
|
33
|
-
await this.#httpServer.start();
|
|
34
|
-
|
|
35
|
-
const services = require("../services");
|
|
36
|
-
|
|
37
|
-
await this.#registerServices(services);
|
|
38
|
-
await this.#registerServices(this.#services);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
for (const [name] of [...services, ...this.#services]) {
|
|
42
|
-
this.container.get('logger').debug(`Booting service ${name}`);
|
|
43
|
-
await this.container.get(name).boot({
|
|
44
|
-
httpServer: this.#httpServer.server,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
for (const extension of this.#extensions) {
|
|
49
|
-
if (!(extension instanceof Extension)) {
|
|
50
|
-
throw new Error(`Extension ${extension.name} is not an instance of Extension class`);
|
|
51
|
-
}
|
|
52
|
-
this.container.get('logger').debug(`Loading extension ${extension.name}`);
|
|
53
|
-
await extension.load(this.container);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return this;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async #registerServices(servicesToRegister = []) {
|
|
62
|
-
for (const [name, serviceClass, args] of servicesToRegister) {
|
|
63
|
-
this.container.register(name, serviceClass, args.map(arg => {
|
|
64
|
-
if(arg === "@service_container") return this.container;
|
|
65
|
-
if(arg === "@onConnection") return this.#onSocketConnection;
|
|
66
|
-
return arg
|
|
67
|
-
}));
|
|
68
|
-
if(this.container.has("logger")) {
|
|
69
|
-
this.container.get("logger").debug(`Service ${name} registered`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
this.container.compile();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async #loadExtensions() {
|
|
77
|
-
// Load extensions if any
|
|
78
|
-
}
|
|
1
|
+
const {ContainerBuilder} = require("node-dependency-injection");
|
|
2
|
+
const EnvManager = require("../utils/EnvManager");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const HTTPServer = require("./HTTPServer");
|
|
6
|
+
const Extension = require("../extensions/Extension");
|
|
7
|
+
|
|
8
|
+
module.exports = class Kernel {
|
|
9
|
+
container;
|
|
10
|
+
#services;
|
|
11
|
+
#onSocketConnection;
|
|
12
|
+
#httpServer;
|
|
13
|
+
#extensions = [];
|
|
14
|
+
|
|
15
|
+
constructor({
|
|
16
|
+
services = [],
|
|
17
|
+
extensions = [],
|
|
18
|
+
} = { }) {
|
|
19
|
+
this.container = new ContainerBuilder();
|
|
20
|
+
this.#services = services;
|
|
21
|
+
this.#extensions = extensions;
|
|
22
|
+
|
|
23
|
+
// create src folder if not exists
|
|
24
|
+
if (!fs.existsSync(path.join(process.cwd(), "src"))) {
|
|
25
|
+
fs.mkdirSync(path.join(process.cwd(), "src"));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async boot(clearConsole = true, secretsPath = `${process.cwd()}/.env`) {
|
|
30
|
+
EnvManager.load(secretsPath, false);
|
|
31
|
+
if(clearConsole) process.stdout.write("\u001b[2J\u001b[0;0H");
|
|
32
|
+
this.#httpServer = new HTTPServer({ port: Number(process.env.PORT) || 3000 });
|
|
33
|
+
await this.#httpServer.start();
|
|
34
|
+
|
|
35
|
+
const services = require("../services");
|
|
36
|
+
|
|
37
|
+
await this.#registerServices(services);
|
|
38
|
+
await this.#registerServices(this.#services);
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
for (const [name] of [...services, ...this.#services]) {
|
|
42
|
+
this.container.get('logger').debug(`Booting service ${name}`);
|
|
43
|
+
await this.container.get(name).boot({
|
|
44
|
+
httpServer: this.#httpServer.server,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
for (const extension of this.#extensions) {
|
|
49
|
+
if (!(extension instanceof Extension)) {
|
|
50
|
+
throw new Error(`Extension ${extension.name} is not an instance of Extension class`);
|
|
51
|
+
}
|
|
52
|
+
this.container.get('logger').debug(`Loading extension ${extension.name}`);
|
|
53
|
+
await extension.load(this.container);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async #registerServices(servicesToRegister = []) {
|
|
62
|
+
for (const [name, serviceClass, args] of servicesToRegister) {
|
|
63
|
+
this.container.register(name, serviceClass, args.map(arg => {
|
|
64
|
+
if(arg === "@service_container") return this.container;
|
|
65
|
+
if(arg === "@onConnection") return this.#onSocketConnection;
|
|
66
|
+
return arg
|
|
67
|
+
}));
|
|
68
|
+
if(this.container.has("logger")) {
|
|
69
|
+
this.container.get("logger").debug(`Service ${name} registered`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
this.container.compile();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async #loadExtensions() {
|
|
77
|
+
// Load extensions if any
|
|
78
|
+
}
|
|
79
79
|
}
|
package/src/services/Service.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
module.exports = class Service {
|
|
2
|
-
name = null;
|
|
3
|
-
|
|
4
|
-
constructor(name) {
|
|
5
|
-
this.name = name;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
async boot() {
|
|
9
|
-
throw new Error("Method 'boot' must be implemented.");
|
|
10
|
-
}
|
|
1
|
+
module.exports = class Service {
|
|
2
|
+
name = null;
|
|
3
|
+
|
|
4
|
+
constructor(name) {
|
|
5
|
+
this.name = name;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async boot() {
|
|
9
|
+
throw new Error("Method 'boot' must be implemented.");
|
|
10
|
+
}
|
|
11
11
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const AuthService = require('./index.js');
|
|
2
|
-
|
|
3
|
-
const auth = new AuthService({
|
|
4
|
-
get: (serviceName) => {
|
|
5
|
-
}
|
|
6
|
-
});
|
|
7
|
-
|
|
1
|
+
const AuthService = require('./index.js');
|
|
2
|
+
|
|
3
|
+
const auth = new AuthService({
|
|
4
|
+
get: (serviceName) => {
|
|
5
|
+
}
|
|
6
|
+
});
|
|
7
|
+
|
|
8
8
|
module.exports = auth.auth;
|
|
@@ -1,200 +1,200 @@
|
|
|
1
|
-
const Service = require('../Service');
|
|
2
|
-
const { toNodeHandler } = require('better-auth/node');
|
|
3
|
-
const { betterAuth } = require("better-auth");
|
|
4
|
-
const { admin, bearer, organization } = require("better-auth/plugins");
|
|
5
|
-
const { Pool } = require("pg");
|
|
6
|
-
const path = require("path");
|
|
7
|
-
|
|
8
|
-
module.exports = class AuthService extends Service {
|
|
9
|
-
#container;
|
|
10
|
-
client;
|
|
11
|
-
|
|
12
|
-
constructor(container) {
|
|
13
|
-
super('AuthService');
|
|
14
|
-
this.#container = container;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async boot() {
|
|
18
|
-
if (!['postgresql', 'sqlite'].includes(process.env.DATABASE_DIALECT)) {
|
|
19
|
-
throw new Error("AuthService only supports PostgreSQL and SQLite as database dialects");
|
|
20
|
-
}
|
|
21
|
-
this.#addAuthEnvVariables();
|
|
22
|
-
this.client = this.auth;
|
|
23
|
-
const express = this.#container.get('express');
|
|
24
|
-
express.regiterRawAllRoutes("/api/auth/*splat", toNodeHandler(this.auth));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
#addAuthEnvVariables() {
|
|
28
|
-
const EnvManager = require('../../utils/EnvManager');
|
|
29
|
-
const envPath = path.join(process.cwd(), '.env');
|
|
30
|
-
|
|
31
|
-
const secretAdded = EnvManager.addEnvVariable(envPath, 'AUTH_SECRET', 'change-this-secret-in-production');
|
|
32
|
-
if (secretAdded) {
|
|
33
|
-
this.#container.get('logger').info('Added AUTH_SECRET to .env file');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const originsAdded = EnvManager.addEnvVariable(envPath, 'TRUSTED_ORIGINS', 'http://localhost:5173,http://localhost:3000');
|
|
37
|
-
if (originsAdded) {
|
|
38
|
-
this.#container.get('logger').info('Added TRUSTED_ORIGINS to .env file');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const betterAuthUrlAdded = EnvManager.addEnvVariable(envPath, 'BETTER_AUTH_URL', 'http://localhost:3000');
|
|
42
|
-
if (betterAuthUrlAdded) {
|
|
43
|
-
this.#container.get('logger').info('Added BETTER_AUTH_URL to .env file');
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
#getDatabaseConnection() {
|
|
48
|
-
const dialect = process.env.DATABASE_DIALECT;
|
|
49
|
-
|
|
50
|
-
if (dialect === 'sqlite') {
|
|
51
|
-
const Database = require('better-sqlite3');
|
|
52
|
-
const dbPath = process.env.DATABASE_URL || path.join(process.cwd(), 'database.sqlite');
|
|
53
|
-
return new Database(dbPath);
|
|
54
|
-
} else if (dialect === 'postgresql') {
|
|
55
|
-
return new Pool({
|
|
56
|
-
connectionString: process.env.DATABASE_URL || null,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
throw new Error(`Unsupported database dialect: ${dialect}`);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
get plugins() {
|
|
64
|
-
return [];
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
get socialProviders() {
|
|
68
|
-
return {}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
get userAdditionalFields() {
|
|
72
|
-
return {};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
get memberAdditionalFields() {
|
|
76
|
-
return {};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
get organizationAdditionalFields() {
|
|
80
|
-
return {};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
get hooks() {
|
|
84
|
-
return {};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async sendResetPasswordEmail({ user, url, token }, request) {
|
|
88
|
-
throw new Error("sendResetPasswordEmail method not implemented");
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
async sendVerificationEmail({ user, url, token }, request) {
|
|
92
|
-
throw new Error("sendVerificationEmail method not implemented");
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
async sendInvitationEmail(data) {
|
|
96
|
-
throw new Error("sendInvitationEmail method not implemented");
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async allowUserToCreateOrganization(user) {
|
|
100
|
-
throw new Error("allowUserToCreateOrganization method not implemented");
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
get auth() {
|
|
104
|
-
const cache = this.#container.get('cache');
|
|
105
|
-
return betterAuth({
|
|
106
|
-
hooks: this.hooks,
|
|
107
|
-
plugins: [
|
|
108
|
-
admin(),
|
|
109
|
-
bearer(),
|
|
110
|
-
organization({
|
|
111
|
-
schema: {
|
|
112
|
-
organization: {
|
|
113
|
-
additionalFields: this.organizationAdditionalFields
|
|
114
|
-
},
|
|
115
|
-
member: {
|
|
116
|
-
additionalFields: this.memberAdditionalFields
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
allowUserToCreateOrganization: async (user) => {
|
|
120
|
-
return await this.allowUserToCreateOrganization(user);
|
|
121
|
-
},
|
|
122
|
-
async
|
|
123
|
-
return await this.sendInvitationEmail(data);
|
|
124
|
-
}
|
|
125
|
-
}),
|
|
126
|
-
...this.plugins,
|
|
127
|
-
],
|
|
128
|
-
socialProviders: this.socialProviders,
|
|
129
|
-
database: this.#getDatabaseConnection(),
|
|
130
|
-
advanced: {
|
|
131
|
-
crossSubDomainCookies: {
|
|
132
|
-
enabled: true,
|
|
133
|
-
},
|
|
134
|
-
cookie: {
|
|
135
|
-
sameSite: "none",
|
|
136
|
-
secure: true,
|
|
137
|
-
path: "/",
|
|
138
|
-
state: {
|
|
139
|
-
attributes: {
|
|
140
|
-
sameSite: "none",
|
|
141
|
-
secure: true,
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
},
|
|
145
|
-
defaultCookieAttributes: {
|
|
146
|
-
secure: true,
|
|
147
|
-
sameSite: "none",
|
|
148
|
-
},
|
|
149
|
-
cookies: {
|
|
150
|
-
state: {
|
|
151
|
-
attributes: {
|
|
152
|
-
sameSite: "none",
|
|
153
|
-
secure: true,
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
},
|
|
158
|
-
secondaryStorage: {
|
|
159
|
-
get: async (key) => {
|
|
160
|
-
return await cache.get(key);
|
|
161
|
-
},
|
|
162
|
-
set: async (key, value, ttl) => {
|
|
163
|
-
await cache.set(key, value);
|
|
164
|
-
if(ttl) await cache.expire(key, ttl);
|
|
165
|
-
},
|
|
166
|
-
delete: async (key) => {
|
|
167
|
-
await cache.del(key);
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
emailAndPassword: {
|
|
171
|
-
enabled: true,
|
|
172
|
-
requireEmailVerification: false,
|
|
173
|
-
sendResetPassword: async ({ user, url, token }, request) => this.sendResetPasswordEmail({ user, url, token }, request),
|
|
174
|
-
},
|
|
175
|
-
emailVerification: {
|
|
176
|
-
sendVerificationEmail: async ({ user, url, token }, request) => this.sendVerificationEmail({ user, url, token }, request),
|
|
177
|
-
sendOnSignIn: true,
|
|
178
|
-
autoSignInAfterVerification: true,
|
|
179
|
-
},
|
|
180
|
-
user: {
|
|
181
|
-
additionalFields: this.userAdditionalFields
|
|
182
|
-
},
|
|
183
|
-
account: {
|
|
184
|
-
accountLinking: { enabled: true },
|
|
185
|
-
skipStateCookieCheck: true,
|
|
186
|
-
},
|
|
187
|
-
session: {
|
|
188
|
-
expiresIn: 60 * 60 * 24 * 7,
|
|
189
|
-
updateAge: 60 * 60 * 24
|
|
190
|
-
},
|
|
191
|
-
baseURL: process.env.BETTER_AUTH_URL || 'http://localhost:3000',
|
|
192
|
-
secret: process.env.AUTH_SECRET || 'your-secret-key-change-in-production',
|
|
193
|
-
trustedOrigins: process.env.TRUSTED_ORIGINS?.split(',') || ['http://localhost:5173', 'http://localhost:6632']
|
|
194
|
-
})
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
get client() {
|
|
198
|
-
return this.client;
|
|
199
|
-
}
|
|
1
|
+
const Service = require('../Service');
|
|
2
|
+
const { toNodeHandler } = require('better-auth/node');
|
|
3
|
+
const { betterAuth } = require("better-auth");
|
|
4
|
+
const { admin, bearer, organization } = require("better-auth/plugins");
|
|
5
|
+
const { Pool } = require("pg");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
|
|
8
|
+
module.exports = class AuthService extends Service {
|
|
9
|
+
#container;
|
|
10
|
+
client;
|
|
11
|
+
|
|
12
|
+
constructor(container) {
|
|
13
|
+
super('AuthService');
|
|
14
|
+
this.#container = container;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async boot() {
|
|
18
|
+
if (!['postgresql', 'sqlite'].includes(process.env.DATABASE_DIALECT)) {
|
|
19
|
+
throw new Error("AuthService only supports PostgreSQL and SQLite as database dialects");
|
|
20
|
+
}
|
|
21
|
+
this.#addAuthEnvVariables();
|
|
22
|
+
this.client = this.auth;
|
|
23
|
+
const express = this.#container.get('express');
|
|
24
|
+
express.regiterRawAllRoutes("/api/auth/*splat", toNodeHandler(this.auth));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
#addAuthEnvVariables() {
|
|
28
|
+
const EnvManager = require('../../utils/EnvManager');
|
|
29
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
30
|
+
|
|
31
|
+
const secretAdded = EnvManager.addEnvVariable(envPath, 'AUTH_SECRET', 'change-this-secret-in-production');
|
|
32
|
+
if (secretAdded) {
|
|
33
|
+
this.#container.get('logger').info('Added AUTH_SECRET to .env file');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const originsAdded = EnvManager.addEnvVariable(envPath, 'TRUSTED_ORIGINS', 'http://localhost:5173,http://localhost:3000');
|
|
37
|
+
if (originsAdded) {
|
|
38
|
+
this.#container.get('logger').info('Added TRUSTED_ORIGINS to .env file');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const betterAuthUrlAdded = EnvManager.addEnvVariable(envPath, 'BETTER_AUTH_URL', 'http://localhost:3000');
|
|
42
|
+
if (betterAuthUrlAdded) {
|
|
43
|
+
this.#container.get('logger').info('Added BETTER_AUTH_URL to .env file');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
#getDatabaseConnection() {
|
|
48
|
+
const dialect = process.env.DATABASE_DIALECT;
|
|
49
|
+
|
|
50
|
+
if (dialect === 'sqlite') {
|
|
51
|
+
const Database = require('better-sqlite3');
|
|
52
|
+
const dbPath = process.env.DATABASE_URL || path.join(process.cwd(), 'database.sqlite');
|
|
53
|
+
return new Database(dbPath);
|
|
54
|
+
} else if (dialect === 'postgresql') {
|
|
55
|
+
return new Pool({
|
|
56
|
+
connectionString: process.env.DATABASE_URL || null,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
throw new Error(`Unsupported database dialect: ${dialect}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
get plugins() {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
get socialProviders() {
|
|
68
|
+
return {}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get userAdditionalFields() {
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get memberAdditionalFields() {
|
|
76
|
+
return {};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
get organizationAdditionalFields() {
|
|
80
|
+
return {};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
get hooks() {
|
|
84
|
+
return {};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async sendResetPasswordEmail({ user, url, token }, request) {
|
|
88
|
+
throw new Error("sendResetPasswordEmail method not implemented");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async sendVerificationEmail({ user, url, token }, request) {
|
|
92
|
+
throw new Error("sendVerificationEmail method not implemented");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async sendInvitationEmail(data) {
|
|
96
|
+
throw new Error("sendInvitationEmail method not implemented");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async allowUserToCreateOrganization(user) {
|
|
100
|
+
throw new Error("allowUserToCreateOrganization method not implemented");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
get auth() {
|
|
104
|
+
const cache = this.#container.get('cache');
|
|
105
|
+
return betterAuth({
|
|
106
|
+
hooks: this.hooks,
|
|
107
|
+
plugins: [
|
|
108
|
+
admin(),
|
|
109
|
+
bearer(),
|
|
110
|
+
organization({
|
|
111
|
+
schema: {
|
|
112
|
+
organization: {
|
|
113
|
+
additionalFields: this.organizationAdditionalFields
|
|
114
|
+
},
|
|
115
|
+
member: {
|
|
116
|
+
additionalFields: this.memberAdditionalFields
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
allowUserToCreateOrganization: async (user) => {
|
|
120
|
+
return await this.allowUserToCreateOrganization(user);
|
|
121
|
+
},
|
|
122
|
+
sendInvitationEmail: async (data) => {
|
|
123
|
+
return await this.sendInvitationEmail(data);
|
|
124
|
+
}
|
|
125
|
+
}),
|
|
126
|
+
...this.plugins,
|
|
127
|
+
],
|
|
128
|
+
socialProviders: this.socialProviders,
|
|
129
|
+
database: this.#getDatabaseConnection(),
|
|
130
|
+
advanced: {
|
|
131
|
+
crossSubDomainCookies: {
|
|
132
|
+
enabled: true,
|
|
133
|
+
},
|
|
134
|
+
cookie: {
|
|
135
|
+
sameSite: "none",
|
|
136
|
+
secure: true,
|
|
137
|
+
path: "/",
|
|
138
|
+
state: {
|
|
139
|
+
attributes: {
|
|
140
|
+
sameSite: "none",
|
|
141
|
+
secure: true,
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
defaultCookieAttributes: {
|
|
146
|
+
secure: true,
|
|
147
|
+
sameSite: "none",
|
|
148
|
+
},
|
|
149
|
+
cookies: {
|
|
150
|
+
state: {
|
|
151
|
+
attributes: {
|
|
152
|
+
sameSite: "none",
|
|
153
|
+
secure: true,
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
secondaryStorage: {
|
|
159
|
+
get: async (key) => {
|
|
160
|
+
return await cache.get(key);
|
|
161
|
+
},
|
|
162
|
+
set: async (key, value, ttl) => {
|
|
163
|
+
await cache.set(key, value);
|
|
164
|
+
if(ttl) await cache.expire(key, ttl);
|
|
165
|
+
},
|
|
166
|
+
delete: async (key) => {
|
|
167
|
+
await cache.del(key);
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
emailAndPassword: {
|
|
171
|
+
enabled: true,
|
|
172
|
+
requireEmailVerification: false,
|
|
173
|
+
sendResetPassword: async ({ user, url, token }, request) => this.sendResetPasswordEmail({ user, url, token }, request),
|
|
174
|
+
},
|
|
175
|
+
emailVerification: {
|
|
176
|
+
sendVerificationEmail: async ({ user, url, token }, request) => this.sendVerificationEmail({ user, url, token }, request),
|
|
177
|
+
sendOnSignIn: true,
|
|
178
|
+
autoSignInAfterVerification: true,
|
|
179
|
+
},
|
|
180
|
+
user: {
|
|
181
|
+
additionalFields: this.userAdditionalFields
|
|
182
|
+
},
|
|
183
|
+
account: {
|
|
184
|
+
accountLinking: { enabled: true },
|
|
185
|
+
skipStateCookieCheck: true,
|
|
186
|
+
},
|
|
187
|
+
session: {
|
|
188
|
+
expiresIn: 60 * 60 * 24 * 7,
|
|
189
|
+
updateAge: 60 * 60 * 24
|
|
190
|
+
},
|
|
191
|
+
baseURL: process.env.BETTER_AUTH_URL || 'http://localhost:3000',
|
|
192
|
+
secret: process.env.AUTH_SECRET || 'your-secret-key-change-in-production',
|
|
193
|
+
trustedOrigins: process.env.TRUSTED_ORIGINS?.split(',') || ['http://localhost:5173', 'http://localhost:6632']
|
|
194
|
+
})
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
get client() {
|
|
198
|
+
return this.client;
|
|
199
|
+
}
|
|
200
200
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
module.exports = class Worker {
|
|
2
|
-
name;
|
|
3
|
-
queueName = null;
|
|
4
|
-
|
|
5
|
-
constructor(name) {
|
|
6
|
-
this.name = name;
|
|
7
|
-
}
|
|
1
|
+
module.exports = class Worker {
|
|
2
|
+
name;
|
|
3
|
+
queueName = null;
|
|
4
|
+
|
|
5
|
+
constructor(name) {
|
|
6
|
+
this.name = name;
|
|
7
|
+
}
|
|
8
8
|
}
|