This pull request introduces new routes for managing admin functions within the Express application. The routes include registration, login, and a protected endpoint accessible only to authenticated admins.
Changes Made:
Added /register Route:
Method:POST
Handler:registerAdmin from adminController
Description: Allows new admins to register.
Added /login Route:
Method:POST
Handler:loginAdmin from adminController
Description: Handles admin login and generates an authentication token.
Added /protected Route:
Method:GET
Middleware:authenticateToken and isAdmin
Description: A protected route accessible only to admins with a valid token.
Code:
const express = require('express');
const router = express.Router();
const { registerAdmin, loginAdmin } = require('../controllers/adminController');
const { authenticateToken, isAdmin } = require('../middleware/authMiddleware');
// Route to handle admin registration
router.post('/register', registerAdmin);
// Route to handle admin login
router.post('/login', loginAdmin);
// Protected route that only admins can access
router.get('/protected', authenticateToken, isAdmin, (req, res) => {
res.status(200).json({ message: 'This is a protected admin route.' });
});
module.exports = router;
Description:
This pull request introduces new routes for managing admin functions within the Express application. The routes include registration, login, and a protected endpoint accessible only to authenticated admins.
Changes Made:
Added
/register
Route:POST
registerAdmin
fromadminController
Added
/login
Route:POST
loginAdmin
fromadminController
Added
/protected
Route:GET
authenticateToken
andisAdmin
Code: