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 findByUserId(userId) {
|
||||
try {
|
||||
const sql = "SELECT* FROM credentials WHERE userId = ?"
|
||||
const sql = "SELECT * FROM credentials WHERE userId = ?"
|
||||
const rows = await pool.query(sql, [userId])
|
||||
return rows[0] || null
|
||||
} catch (error) {
|
||||
@@ -11,20 +11,20 @@ async function findByUserId(userId) {
|
||||
}
|
||||
}
|
||||
|
||||
async function create(userId, hashedPassword) {
|
||||
async function create(userId, passwordHash) {
|
||||
try {
|
||||
const sql = "INSERT INTO credentials (userId, hashedPassword) VALUES (?, ?)"
|
||||
const rows = await pool.query(sql, [userId, hashedPassword])
|
||||
return rows[0] || null
|
||||
const sql = "INSERT INTO credentials (userId, passwordHash) VALUES (?, ?)"
|
||||
const rows = await pool.query(sql, [userId, passwordHash])
|
||||
return rows || null
|
||||
} catch (error) {
|
||||
throw new DefaultError(500, "Internal Server Error", error)
|
||||
}
|
||||
}
|
||||
|
||||
async function updatePassword(userId, hashedPassword) {
|
||||
async function updatePassword(userId, passwordHash) {
|
||||
try {
|
||||
const sql = "UPDATE credentials SET hashedPassword = ? WHERE userId = ?"
|
||||
const rows = await pool.query(sql, [hashedPassword, userId])
|
||||
const sql = "UPDATE credentials SET passwordHash = ? WHERE userId = ?"
|
||||
const rows = await pool.query(sql, [passwordHash, userId])
|
||||
return rows.affectedRows > 0
|
||||
} catch (error) {
|
||||
throw new DefaultError(500, "Internal Server Error", error)
|
||||
|
||||
Reference in New Issue
Block a user