mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-24 04:10:15 +01:00
chore: remove jose as Bun now supports JWT 🍞 (#1167)
* chore: remove jose as Bun now supports JWT * chore: npm audit
This commit is contained in:
parent
9ca84edb9a
commit
5d95433c83
8 changed files with 46 additions and 68 deletions
|
|
@ -1,15 +1,13 @@
|
|||
const crypto = require('crypto');
|
||||
const cookies = require('cookie');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { Session, User } = require('../../models');
|
||||
const {
|
||||
registerUser,
|
||||
requestPasswordReset,
|
||||
resetPassword,
|
||||
setAuthTokens,
|
||||
} = require('../services/AuthService');
|
||||
const jose = require('jose');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const Session = require('../../models/Session');
|
||||
const User = require('../../models/User');
|
||||
const crypto = require('crypto');
|
||||
const cookies = require('cookie');
|
||||
|
||||
const registrationController = async (req, res) => {
|
||||
try {
|
||||
|
|
@ -78,12 +76,7 @@ const refreshController = async (req, res) => {
|
|||
|
||||
try {
|
||||
let payload;
|
||||
if (typeof Bun !== 'undefined') {
|
||||
const secret = new TextEncoder().encode(process.env.JWT_REFRESH_SECRET);
|
||||
({ payload } = await jose.jwtVerify(refreshToken, secret));
|
||||
} else {
|
||||
payload = jwt.verify(refreshToken, process.env.JWT_REFRESH_SECRET);
|
||||
}
|
||||
payload = jwt.verify(refreshToken, process.env.JWT_REFRESH_SECRET);
|
||||
const userId = payload.id;
|
||||
const user = await User.findOne({ _id: userId });
|
||||
if (!user) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ const { PORT, HOST, ALLOW_SOCIAL_LOGIN } = process.env ?? {};
|
|||
const port = Number(PORT) || 3080;
|
||||
const host = HOST || 'localhost';
|
||||
const projectPath = path.join(__dirname, '..', '..', 'client');
|
||||
const { jwtLogin, joseLogin, passportLogin } = require('../strategies');
|
||||
const { jwtLogin, passportLogin } = require('../strategies');
|
||||
|
||||
const startServer = async () => {
|
||||
await connectDb();
|
||||
|
|
@ -39,11 +39,7 @@ const startServer = async () => {
|
|||
|
||||
// OAUTH
|
||||
app.use(passport.initialize());
|
||||
if (typeof Bun !== 'undefined') {
|
||||
passport.use('jwt', await joseLogin());
|
||||
} else {
|
||||
passport.use(await jwtLogin());
|
||||
}
|
||||
passport.use(await jwtLogin());
|
||||
passport.use(passportLogin());
|
||||
|
||||
if (ALLOW_SOCIAL_LOGIN?.toLowerCase() === 'true') {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
const jose = require('jose');
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
/**
|
||||
|
|
@ -21,15 +20,6 @@ const jwt = require('jsonwebtoken');
|
|||
* });
|
||||
*/
|
||||
async function signPayload({ payload, secret, expirationTime }) {
|
||||
if (typeof Bun !== 'undefined') {
|
||||
// this code will only run when the file is run with Bun
|
||||
const encodedSecret = new TextEncoder().encode(secret);
|
||||
return await new jose.SignJWT(payload)
|
||||
.setProtectedHeader({ alg: 'HS256' })
|
||||
.setExpirationTime(expirationTime + 's')
|
||||
.sign(encodedSecret);
|
||||
}
|
||||
|
||||
return jwt.sign(payload, secret, { expiresIn: expirationTime });
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue