Add auth, JWT tokens, and bootstrap startup

Introduce bootstrap entrypoint and prestartup to ping DB and generate/manage RSA keypair. Add security module for key IO. Implement JWT-based access and refresh tokens (tokensService) with refresh_tokens table and repo. Add auth, provider and user services, and refresh-token management. Update repositories (users, credentials, providers, servers) with SQL fixes and new helper methods. Move DDL execution to bootstrap (remove from server). Update package.json main and add dependencies (bcryptjs, jsonwebtoken). Update .env.example and .gitignore accordingly.
This commit is contained in:
2026-09-02 01:55:58 +02:00
parent 7a87a98c82
commit 22542243f6
20 changed files with 686 additions and 28 deletions
+14 -3
View File
@@ -3,7 +3,7 @@ const { DefaultError } = require("../errors/errors")
async function findById(id) {
try {
const sql = "SELECT* FROM providers WHERE id = ?"
const sql = "SELECT * FROM providers WHERE id = ?"
const rows = await pool.query(sql, [id])
return rows[0] || null
} catch (error) {
@@ -13,7 +13,7 @@ async function findById(id) {
async function findByName(id) {
try {
const sql = "SELECT* FROM providers WHERE name = ?"
const sql = "SELECT * FROM providers WHERE name = ?"
const rows = await pool.query(sql, [id])
return rows[0] || null
} catch (error) {
@@ -23,7 +23,7 @@ async function findByName(id) {
async function listEnabled() {
try {
const sql = "SELECT* FROM providers WHERE isEnabled = ?"
const sql = "SELECT * FROM providers WHERE isEnabled = ?"
const rows = await pool.query(sql, [true])
return rows || []
} catch (error) {
@@ -31,6 +31,16 @@ async function listEnabled() {
}
}
async function listAll() {
try {
const sql = "SELECT * FROM providers"
const rows = await pool.query(sql)
return rows || []
} catch (error) {
throw new DefaultError(500, "Internal Server Error", error)
}
}
async function setEnabled(id, isEnabled) {
try {
const sql = "UPDATE providers SET isEnabled = ? WHERE id = ?"
@@ -97,6 +107,7 @@ async function remove(id) {
module.exports = {
remove,
create,
listAll,
findById,
findByName,
setEnabled,