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
+18 -4
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 users WHERE id = ?"
const rows = await pool.query(sql, [id])
return rows[0] || null
} catch (error) {
@@ -11,16 +11,29 @@ async function findById(id) {
}
}
async function create(serverId, remoteId = null, displayName, avatarUrl) {
async function findByIdentifier(identifier) {
try {
const sql = "INSERT INTO users (serverId, remoteId, displayName, avatarUrl) VALUES (?, ?, ?, ?)"
const rows = await pool.query(sql, [serverId, remoteId, displayName, avatarUrl])
const sql = "SELECT * FROM users WHERE identifier = ?"
const rows = await pool.query(sql, [identifier])
return rows[0] || null
} catch (error) {
throw new DefaultError(500, "Internal Server Error", error)
}
}
async function create(identifier, serverId, remoteId = null, displayName, avatarUrl) {
try {
const sql = "INSERT INTO users (identifier, serverId, remoteId, displayName, avatarUrl) VALUES (?, ?, ?, ?, ?) RETURNING *"
const rows = await pool.query(sql, [identifier, serverId, remoteId, displayName, avatarUrl])
return rows[0] || null
} catch (error) {
if (error.code && error.code == "ER_DUP_ENTRY") {
throw new DefaultError(401, "Identifier already taken.", "Identifier already assigned.")
}
throw new DefaultError(500, "Internal Server Error", error)
}
}
async function remove(id) {
try {
const sql = "DELETE FROM users WHERE id = ?"
@@ -86,5 +99,6 @@ module.exports = {
isLocal,
findById,
updateProfile,
findByIdentifier,
findByServerAndRemoteId
}