Add admin login and password change endpoints
Introduces POST /login and PATCH /password routes for admin authentication and password management. Adds corresponding schema validation for login and password change, enforces stricter password requirements, and updates adminService with JWT-based profile retrieval and improved token handling.
This commit is contained in:
@@ -1,4 +1,21 @@
|
||||
const express = require("express")
|
||||
const router = express.Router()
|
||||
const router = express.Router()
|
||||
const adminService = require("../../services/adminService")
|
||||
|
||||
router.post("/login", async (req, res) => {
|
||||
const { username, password } = req.body
|
||||
const result = await adminService.loginAdmin(username, password)
|
||||
return res.status(200).json(result)
|
||||
})
|
||||
|
||||
router.patch("/password", async (req, res) => {
|
||||
const token = req.headers.authorization.replace("Bearer ", "")
|
||||
const profile = await adminService.getAdminProfileByToken(token)
|
||||
|
||||
const { newPassword } = req.body
|
||||
|
||||
const result = await adminService.changeAdminPassword(profile.id, newPassword)
|
||||
return res.status(200).json(result)
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
Reference in New Issue
Block a user