zyket 1.2.3 → 1.2.4
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
CHANGED
|
@@ -3,6 +3,7 @@ const { toNodeHandler } = require('better-auth/node');
|
|
|
3
3
|
const { betterAuth } = require("better-auth");
|
|
4
4
|
const { admin, bearer, organization } = require("better-auth/plugins");
|
|
5
5
|
const { Pool } = require("pg");
|
|
6
|
+
const path = require("path");
|
|
6
7
|
|
|
7
8
|
module.exports = class AuthService extends Service {
|
|
8
9
|
#container;
|
|
@@ -14,12 +15,46 @@ module.exports = class AuthService extends Service {
|
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
async boot() {
|
|
17
|
-
if(process.env.DATABASE_DIALECT
|
|
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();
|
|
18
22
|
this.client = this.auth;
|
|
19
23
|
const express = this.#container.get('express');
|
|
20
24
|
express.regiterRawAllRoutes("/api/auth/*splat", toNodeHandler(this.auth));
|
|
21
25
|
}
|
|
22
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
|
+
|
|
42
|
+
#getDatabaseConnection() {
|
|
43
|
+
const dialect = process.env.DATABASE_DIALECT;
|
|
44
|
+
|
|
45
|
+
if (dialect === 'sqlite') {
|
|
46
|
+
const Database = require('better-sqlite3');
|
|
47
|
+
const dbPath = process.env.DATABASE_URL || path.join(process.cwd(), 'database.sqlite');
|
|
48
|
+
return new Database(dbPath);
|
|
49
|
+
} else if (dialect === 'postgresql') {
|
|
50
|
+
return new Pool({
|
|
51
|
+
connectionString: process.env.DATABASE_URL || null,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
throw new Error(`Unsupported database dialect: ${dialect}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
23
58
|
get plugins() {
|
|
24
59
|
return [];
|
|
25
60
|
}
|
|
@@ -86,9 +121,7 @@ module.exports = class AuthService extends Service {
|
|
|
86
121
|
...this.plugins,
|
|
87
122
|
],
|
|
88
123
|
socialProviders: this.socialProviders,
|
|
89
|
-
database:
|
|
90
|
-
connectionString: process.env.DATABASE_URL || null,
|
|
91
|
-
}),
|
|
124
|
+
database: this.#getDatabaseConnection(),
|
|
92
125
|
advanced: {
|
|
93
126
|
crossSubDomainCookies: {
|
|
94
127
|
enabled: true,
|
package/src/utils/EnvManager.js
CHANGED
|
@@ -20,8 +20,8 @@ module.exports = class EnvManager {
|
|
|
20
20
|
DISABLE_EVENTS: true,
|
|
21
21
|
DISABLE_BULLMQ: true,
|
|
22
22
|
DISABLE_SCHEDULER: true,
|
|
23
|
-
DATABASE_URL: '',
|
|
24
|
-
DATABASE_DIALECT: '
|
|
23
|
+
DATABASE_URL: './database.sqlite',
|
|
24
|
+
DATABASE_DIALECT: 'sqlite',
|
|
25
25
|
CACHE_URL: '',
|
|
26
26
|
S3_ENDPOINT: '',
|
|
27
27
|
S3_PORT: '',
|