-ต้นแบบ โครงสร้าง ไฟล์ API เส้น /api/ttc

This commit is contained in:
2025-11-17 09:03:36 +07:00
parent eefbb8e5dd
commit 9f9c9aa80d
25 changed files with 1019 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
import { verifyToken } from '../utils/token.js'
import { sendError } from '../utils/response.js'
export function authMiddleware(req, res, next) {
const authHeader = req.headers['authorization']
const token = authHeader && authHeader.split(' ')[1]
if (!token) return sendError('ไม่พบ Token', 'Missing token', 401)
const decoded = verifyToken(token)
if (!decoded) return sendError('Token ไม่ถูกต้อง', 'Invalid token', 403)
req.user = decoded
next()
}