-first commit

This commit is contained in:
2025-11-11 12:36:06 +07:00
commit b99c214434
5683 changed files with 713336 additions and 0 deletions

View File

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