mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00
26 lines
648 B
JavaScript
26 lines
648 B
JavaScript
const { Strategy: JwtStrategy, ExtractJwt } = require('passport-jwt');
|
|
const User = require('../models/User');
|
|
|
|
// JWT strategy
|
|
const jwtLogin = async () =>
|
|
new JwtStrategy(
|
|
{
|
|
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
secretOrKey: process.env.JWT_SECRET,
|
|
},
|
|
async (payload, done) => {
|
|
try {
|
|
const user = await User.findById(payload.id);
|
|
if (user) {
|
|
done(null, user);
|
|
} else {
|
|
console.log('JwtStrategy => no user found');
|
|
done(null, false);
|
|
}
|
|
} catch (err) {
|
|
done(err, false);
|
|
}
|
|
},
|
|
);
|
|
|
|
module.exports = jwtLogin;
|