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 servers WHERE id = ?"
const sql = "SELECT * FROM servers 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 findByUrl(url) {
try {
const sql = "SELECT* FROM servers WHERE url = ?"
const sql = "SELECT * FROM servers WHERE url = ?"
const rows = await pool.query(sql, [url])
return rows[0] || null
} catch (error) {
@@ -31,6 +31,16 @@ async function create(url, publicKey) {
}
}
async function createAndAssignIdManually(id, url, publicKey) {
try {
const sql = "INSERT INTO servers (id, serverUrl, publicKey) VALUES (?, ?, ?)"
const rows = await pool.query(sql, [id, url, publicKey])
return rows[0] || null
} catch (error) {
throw new DefaultError(500, "Internal Server Error", error)
}
}
async function remove(id) {
try {
const sql = "DELETE FROM servers WHERE id = ?"
@@ -74,5 +84,6 @@ module.exports = {
remove,
findById,
findByUrl,
updateServer
updateServer,
createAndAssignIdManually
}