Add Minecraft services API routes and user service
Introduces new routes under /minecraftservices and /mojangapi for profile, skin, cape, blocklist, privileges, and certificate management. Adds a comprehensive userService module to handle user-related operations, and extends userRepository with methods for username changes, skin/cape management, blocking, and profile lookups. Refactors username availability logic into authService, updates error handling, and improves logger and utility functions. Also updates route handlers to use consistent return statements and enhances route registration logging.
This commit is contained in:
@@ -11,7 +11,7 @@ const limiter = rateLimit({
|
||||
standardHeaders: true,
|
||||
legacyHeaders: false,
|
||||
handler: (req, res) => {
|
||||
res.status(429).json({
|
||||
return res.status(429).json({
|
||||
error: "TooManyRequestsException",
|
||||
errorMessage: "Too many login attempts, please try again later."
|
||||
})
|
||||
@@ -29,7 +29,7 @@ router.post("/", limiter, async (req, res) => {
|
||||
})
|
||||
|
||||
logger.log(`User authenticated: ${username}`, ["AUTH", "green"])
|
||||
res.status(200).json(result.response)
|
||||
return res.status(200).json(result.response)
|
||||
} catch (err) {
|
||||
if (err instanceof DefaultError) {
|
||||
throw new YggdrasilError( err.code, err.error || "ForbiddenOperationException", err.message, "Invalid credentials")
|
||||
|
||||
@@ -8,7 +8,7 @@ router.post("/", async (req, res) => {
|
||||
const { accessToken, clientToken } = req.body
|
||||
try {
|
||||
await authService.invalidate({ accessToken, clientToken })
|
||||
res.sendStatus(204)
|
||||
return res.sendStatus(204)
|
||||
} catch (err) {
|
||||
if (err instanceof DefaultError) {
|
||||
throw new YggdrasilError(err.code, err.error || "ForbiddenOperationException", err.message, "Invalid token.")
|
||||
|
||||
@@ -16,9 +16,7 @@ router.post("/", async (req, res) => {
|
||||
|
||||
const profileName = result.response.selectedProfile ? result.response.selectedProfile.name : "Unknown"
|
||||
logger.log(`Session refreshed for: ${profileName}`, ["AUTH", "green"])
|
||||
|
||||
res.status(200).json(result.response)
|
||||
|
||||
return res.status(200).json(result.response)
|
||||
} catch (err) {
|
||||
if (err instanceof DefaultError) {
|
||||
throw new YggdrasilError(err.code, err.error || "ForbiddenOperationException", err.message, "Invalid token.")
|
||||
|
||||
@@ -17,8 +17,7 @@ router.post("/", async (req, res) => {
|
||||
await authService.signout({ uuid: userUuid })
|
||||
|
||||
logger.log(`User signed out globally: ${username}`, ["AUTH", "green"])
|
||||
res.sendStatus(204)
|
||||
|
||||
return res.sendStatus(204)
|
||||
} catch (err) {
|
||||
if (err instanceof DefaultError) {
|
||||
throw new YggdrasilError(err.code === 403 ? 403 : 500, err.error || "ForbiddenOperationException", err.message || "Invalid credentials.", "Invalid credentials.")
|
||||
|
||||
@@ -8,7 +8,7 @@ router.post("/", async (req, res) => {
|
||||
const { accessToken, clientToken } = req.body
|
||||
try {
|
||||
await authService.validate({ accessToken, clientToken })
|
||||
res.sendStatus(204)
|
||||
return res.sendStatus(204)
|
||||
} catch (err) {
|
||||
if (err instanceof DefaultError) {
|
||||
throw new YggdrasilError(err.code, err.error || "ForbiddenOperationException", err.message, "Invalid token.")
|
||||
|
||||
Reference in New Issue
Block a user