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:
@@ -1,11 +1,13 @@
|
||||
CREATE TABLE IF NOT EXISTS `users` (
|
||||
`id` UUID PRIMARY KEY DEFAULT UUID(),
|
||||
`role` VARCHAR(16) NOT NULL DEFAULT 'user',
|
||||
`serverId` UUID NULL,
|
||||
`identifier` VARCHAR(255) NOT NULL UNIQUE,
|
||||
`remoteId` VARCHAR(255) NULL,
|
||||
`displayName` VARCHAR(512) NOT NULL,
|
||||
`avatarUrl` TEXT NULL,
|
||||
`createdAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`identifier` VARCHAR(255) NOT NULL UNIQUE,
|
||||
`isDisabled` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
`displayName` VARCHAR(512) NOT NULL,
|
||||
|
||||
CONSTRAINT `fk_users_serverId` FOREIGN KEY (`serverId`) REFERENCES `servers` (`id`) ON DELETE CASCADE,
|
||||
CONSTRAINT `uq_users_server_remote` UNIQUE (`serverId`, `remoteId`)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
CREATE TABLE IF NOT EXISTS `credentials` (
|
||||
`userId` UUID PRIMARY KEY,
|
||||
`passwordHash` TEXT NOT NULL,
|
||||
`shouldReset` BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
`updatedAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT `fk_credentials_userId` FOREIGN KEY (`userId`) REFERENCES `users` (`id`) ON DELETE CASCADE
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
CREATE TABLE IF NOT EXISTS `bans` (
|
||||
`id` UUID PRIMARY KEY DEFAULT UUID(),
|
||||
`userId` UUID NOT NULL,
|
||||
`message` TEXT NOT NULL,
|
||||
`isActive` BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
`expiresAt` TIMESTAMP NOT NULL,
|
||||
`createdAt` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT `fk_ban_userId` FOREIGN KEY (`userId`) REFERENCES `users` (`id`) ON DELETE CASCADE
|
||||
)
|
||||
Reference in New Issue
Block a user