WIP
This commit is contained in:
parent
fe1cd3f2da
commit
b50d496e75
1
package-lock.json
generated
1
package-lock.json
generated
@ -50,6 +50,7 @@
|
||||
"jwt-decode": "~3.1.2",
|
||||
"kafkajs": "^2.2.4",
|
||||
"knex": "~3.1.0",
|
||||
"kysely": "^0.28.8",
|
||||
"limiter": "~2.1.0",
|
||||
"liquidjs": "^10.7.0",
|
||||
"marked": "^14.0.0",
|
||||
|
||||
@ -104,6 +104,7 @@
|
||||
"jwt-decode": "~3.1.2",
|
||||
"kafkajs": "^2.2.4",
|
||||
"knex": "~3.1.0",
|
||||
"kysely": "^0.28.8",
|
||||
"limiter": "~2.1.0",
|
||||
"liquidjs": "^10.7.0",
|
||||
"marked": "^14.0.0",
|
||||
|
||||
56
server/better-auth.js
Normal file
56
server/better-auth.js
Normal file
@ -0,0 +1,56 @@
|
||||
const { betterAuth } = require("better-auth");
|
||||
const { Kysely, SqliteDialect } = require("kysely");
|
||||
const { R } = require("redbean-node");
|
||||
const Database = require("./database");
|
||||
|
||||
let auth = undefined;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function getAuth() {
|
||||
if (!auth) {
|
||||
auth = betterAuth({
|
||||
database: await getDatabase(),
|
||||
secret: "TODO-testing-secret-change-me",
|
||||
trustedOrigins: [ "*" ],
|
||||
emailAndPassword: {
|
||||
enabled: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
return auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Kysely dialect for SQLite.
|
||||
* @param {sqlite3.Database} database The SQLite database instance.
|
||||
* @returns {SqliteDialect} The Kysely SQLite dialect.
|
||||
*/
|
||||
function createSQLiteKyselyDialect(database) {
|
||||
return new SqliteDialect({
|
||||
database,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
async function getDatabase() {
|
||||
const rawConn = await R.knex.client.acquireConnection();
|
||||
|
||||
console.log(rawConn.run);
|
||||
|
||||
if (Database.dbConfig.type === "sqlite") {
|
||||
console.log("Creating Kysely SQLite dialect");
|
||||
return new Kysely({
|
||||
dialect: createSQLiteKyselyDialect(rawConn),
|
||||
});
|
||||
} else {
|
||||
return rawConn;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getAuth,
|
||||
};
|
||||
@ -151,6 +151,7 @@ const { resetChrome } = require("./monitor-types/real-browser-monitor-type");
|
||||
const { EmbeddedMariaDB } = require("./embedded-mariadb");
|
||||
const { SetupDatabase } = require("./setup-database");
|
||||
const { chartSocketHandler } = require("./socket-handlers/chart-socket-handler");
|
||||
const { getAuth } = require("./better-auth");
|
||||
|
||||
app.use(express.json());
|
||||
|
||||
@ -1758,6 +1759,9 @@ async function initDatabase(testMode = false) {
|
||||
await Database.connect(testMode);
|
||||
log.info("server", "Connected to the database");
|
||||
|
||||
log.debug("server", "Init Better Auth");
|
||||
const auth = getAuth();
|
||||
|
||||
// Patch the database
|
||||
await Database.patch(port, hostname);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user