Add base project files including environment example, license, README, .gitignore, error classes, ESLint config, database modules, texture assets, repositories, routes, schemas, services, and server entry point. This establishes the foundational structure for a Yggdrasil-compatible REST API with modular error handling, database setup, and route organization.
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 |