LibreChat/api/server/middleware/setTwoFactorTempUser.js
Danny Avila 5011be4d38
🚦 fix: Guard Auth Continuation with Dedicated Limiter (#13555)
* fix: refine auth continuation handling

* test: align auth route mock setup

* fix: separate auth continuation throttling

* test: format auth route mock

* fix: preserve continuation limiter context

* fix: hydrate continuation user before bans
2026-06-06 14:21:28 -04:00

25 lines
482 B
JavaScript

const jwt = require('jsonwebtoken');
const setTwoFactorTempUser = (req, _res, next) => {
if (req.user?.id || req.user?._id) {
return next();
}
const { tempToken } = req.body ?? {};
if (!tempToken) {
return next();
}
try {
const payload = jwt.verify(tempToken, process.env.JWT_SECRET);
if (payload?.userId) {
req.user = { id: payload.userId };
}
} catch {
return next();
}
return next();
};
module.exports = setTwoFactorTempUser;