began to refactor backend

This commit is contained in:
2025-11-05 10:25:23 +01:00
parent 3e67bf9052
commit 27d21efefa
12 changed files with 141 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
import express from "express";
import { authenticate, generateToken } from "../services/tokenService.js";
const router = express.Router();
import nodemailer from "nodemailer";
import dotenv from "dotenv";
dotenv.config();
// database funcs import
import { loginFunc } from "./database/userMgmt.database.js";
router.post("/login", async (req, res) => {
const result = await loginFunc(req.body.username, req.body.password);
if (result.success) {
const token = await generateToken({
username: result.data.username,
role: result.data.role,
});
res.status(200).json({ message: "Login successful", token });
} else {
res.status(401).json({ message: "Invalid credentials" });
}
});