generated from azures04/Base-REST-API
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).
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
const userRepo = require("../repositories/usersRepo")
|
|
const cache = require("../modules/cache")
|
|
|
|
async function getProfile({ userId }) {
|
|
const cachedUser = cache.users.get(userId)
|
|
if (cachedUser) {
|
|
return cachedUser
|
|
}
|
|
return await userRepo.findById(userId)
|
|
}
|
|
|
|
async function updateProfile({ userId, profile = { displayName, avatarURL } }) {
|
|
cache.users.delete(userId)
|
|
return await userRepo.updateProfile(userId, profile.displayName, profile.avatarURL)
|
|
}
|
|
|
|
async function deleteAccount({ userId }) {
|
|
return await userRepo.remove(userId)
|
|
}
|
|
|
|
async function isLocal({ userId }) {
|
|
return await userRepo.isLocal(userId)
|
|
}
|
|
|
|
async function createUser({ identifier, serverId, remoteId = null, profile = { displayName, avatarUrl } }) {
|
|
return await userRepo.create(identifier, serverId, remoteId, profile.displayName, profile.avatarUrl)
|
|
}
|
|
|
|
async function getShadowUser({ serverId, remoteId }) {
|
|
return await userRepo.findByServerAndRemoteId(serverId, remoteId)
|
|
}
|
|
|
|
module.exports = {
|
|
isLocal,
|
|
getProfile,
|
|
createUser,
|
|
updateProfile,
|
|
deleteAccount,
|
|
getShadowUser
|
|
} |