- Updated LoanTable component to fetch loan data from new API endpoint and display notes. - Enhanced UserTable component to include additional user fields (first name, last name, email, admin status) and updated input handling. - Modified fetcher utility to use new user data API endpoint. - Adjusted login functionality to point to the new admin login endpoint and handle unauthorized access. - Refactored user actions utility to align with updated API endpoints for user management. - Updated backend routes for user and loan data management to reflect new structure and naming conventions. - Revised SQL schema and mock data to accommodate new fields and constraints. - Changed Docker configuration to use the new database name.
25 lines
742 B
JavaScript
25 lines
742 B
JavaScript
import express from "express";
|
|
import { authenticate, generateToken } from "../../services/authentication.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" });
|
|
}
|
|
});
|
|
|
|
export default router;
|