mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-06-10 10:05:18 +00:00
* 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
25 lines
482 B
JavaScript
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;
|