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.
29 lines
1.0 KiB
JavaScript
29 lines
1.0 KiB
JavaScript
const express = require("express")
|
|
const router = express.Router()
|
|
const authService = require("../../services/authService")
|
|
const logger = require("../../modules/logger")
|
|
const { DefaultError, YggdrasilError } = require("../../errors/errors")
|
|
|
|
router.post("/", async (req, res) => {
|
|
const { username, password } = req.body
|
|
try {
|
|
const authResult = await authService.authenticate({
|
|
identifier: username,
|
|
password,
|
|
requireUser: false
|
|
})
|
|
|
|
const userUuid = authResult.response.selectedProfile.id
|
|
await authService.signout({ uuid: userUuid })
|
|
|
|
logger.log(`User signed out globally: ${username}`, ["AUTH", "green"])
|
|
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.")
|
|
}
|
|
throw err
|
|
}
|
|
})
|
|
|
|
module.exports = router |