mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00
18 lines
433 B
JavaScript
18 lines
433 B
JavaScript
![]() |
const passport = require('passport');
|
||
|
|
||
|
// This middleware does not require authentication,
|
||
|
// but if the user is authenticated, it will set the user object.
|
||
|
const optionalJwtAuth = (req, res, next) => {
|
||
|
passport.authenticate('jwt', { session: false }, (err, user) => {
|
||
|
if (err) {
|
||
|
return next(err);
|
||
|
}
|
||
|
if (user) {
|
||
|
req.user = user;
|
||
|
}
|
||
|
next();
|
||
|
})(req, res, next);
|
||
|
};
|
||
|
|
||
|
module.exports = optionalJwtAuth;
|