azures04 0b1662d8ca Initial project structure and core modules
Add environment example, update .gitignore, and switch license to AGPL v3. Introduce error handling classes, ESLint config, and main modules for database, logging, certificate management, and utility functions. Add authentication routes, schemas, and service layer for a modular REST API. Update README and set up repository structure for further development.
2025-12-23 15:59:43 +01:00

32 lines
1.1 KiB
JavaScript

const path = require("node:path")
const express = require("express")
const router = express.Router()
const authService = require("../../services/authService")
const Logger = require("../../modules/logger")
const logger = Logger.createLogger(path.join(__dirname, "..", ".."))
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"])
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