generated from azures04/Base-REST-API
Add bans, user cache, auth routes & token changes
Introduce user bans and caching, extend schemas, and add auth/user endpoints. Adds bans DDL and banRepo plus adminService to manage bans; introduces modules/cache for in-memory user caching used by authService and userService. Updates users and credentials DDLs (role, isDisabled, shouldReset). Changes tokensService to include role in access tokens and store refresh tokens as SHA-256 hashes. Updates repos (credentials create RETURNING, usersRepo.updateProfile positional params), enhances authService with isLogged/isNotLogged middleware, ban checks, and refreshed token flow. Adds auth routes (login, logout, refresh, register) and user routes (/me).
This commit is contained in:
@@ -58,27 +58,30 @@ async function isLocal(id) {
|
||||
async function updateProfile(id, displayName, avatarUrl) {
|
||||
try {
|
||||
const fields = []
|
||||
const params = { id }
|
||||
const params = []
|
||||
|
||||
if (displayName !== undefined) {
|
||||
fields.push('`displayName` = :displayName')
|
||||
params.displayName = displayName
|
||||
fields.push('`displayName` = ?')
|
||||
params.push(displayName)
|
||||
}
|
||||
|
||||
if (avatarUrl !== undefined) {
|
||||
fields.push('`avatarUrl` = :avatarUrl')
|
||||
params.avatarUrl = avatarUrl
|
||||
fields.push('`avatarUrl` = ?')
|
||||
params.push(avatarUrl)
|
||||
}
|
||||
|
||||
if (fields.length === 0) {
|
||||
return findById(id)
|
||||
}
|
||||
|
||||
const sql = `UPDATE users SET ${fields.join(', ')} WHERE id = :id`
|
||||
params.push(id)
|
||||
|
||||
const sql = `UPDATE users SET ${fields.join(', ')} WHERE id = ?`
|
||||
await pool.query(sql, params)
|
||||
|
||||
return findById(id)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
throw new DefaultError(500, "Internal Server Error", error)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user