generated from azures04/Base-REST-API
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:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user