Update bcryptjs to version 3.0.3 and add smoke-tracker router to the server configuration.

This commit is contained in:
Primakov Alexandr Alexandrovich
2025-11-17 13:25:20 +03:00
parent 4c166a8d33
commit f6f9163c3f
15 changed files with 1230 additions and 5 deletions

View File

@@ -0,0 +1,26 @@
const jwt = require('jsonwebtoken')
const { SMOKE_TRACKER_TOKEN_KEY } = require('../const')
const authMiddleware = (req, res, next) => {
const authHeader = req.headers.authorization || ''
const token = authHeader.startsWith('Bearer ')
? authHeader.slice(7)
: null
if (!token) {
throw new Error('Требуется авторизация')
}
try {
const decoded = jwt.verify(token, SMOKE_TRACKER_TOKEN_KEY)
req.user = decoded
next()
} catch (e) {
throw new Error('Неверный или истекший токен авторизации')
}
}
module.exports.authMiddleware = authMiddleware