mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-03-08 00:52:37 +01:00
ci(backend-review.yml): add linter step to the backend review workflow (#625)
* ci(backend-review.yml): add linter step to the backend review workflow * chore(backend-review.yml): remove prettier from lint-action configuration * chore: apply new linting workflow * chore(lint-staged.config.js): reorder lint-staged tasks for JavaScript and TypeScript files * chore(eslint): update ignorePatterns in .eslintrc.js chore(lint-action): remove prettier option in backend-review.yml chore(package.json): add lint and lint:fix scripts * chore(lint-staged.config.js): remove prettier --write command for js, jsx, ts, tsx files * chore(titleConvo.js): remove unnecessary console.log statement chore(titleConvo.js): add missing comma in options object * chore: apply linting to all files * chore(lint-staged.config.js): update lint-staged configuration to include prettier formatting
This commit is contained in:
parent
637bb6bc11
commit
e5336039fc
231 changed files with 1688 additions and 1526 deletions
|
|
@ -10,7 +10,7 @@ const discordLogin = new DiscordStrategy(
|
|||
clientSecret: process.env.DISCORD_CLIENT_SECRET,
|
||||
callbackURL: `${domains.server}${process.env.DISCORD_CALLBACK_URL}`,
|
||||
scope: ['identify', 'email'], // Request scopes
|
||||
authorizationURL: 'https://discord.com/api/oauth2/authorize?prompt=none' // Add the prompt query parameter
|
||||
authorizationURL: 'https://discord.com/api/oauth2/authorize?prompt=none', // Add the prompt query parameter
|
||||
},
|
||||
async (accessToken, refreshToken, profile, cb) => {
|
||||
try {
|
||||
|
|
@ -37,7 +37,7 @@ const discordLogin = new DiscordStrategy(
|
|||
username: profile.username,
|
||||
email,
|
||||
name: profile.global_name,
|
||||
avatar: avatarURL
|
||||
avatar: avatarURL,
|
||||
});
|
||||
|
||||
cb(null, newUser);
|
||||
|
|
@ -45,7 +45,7 @@ const discordLogin = new DiscordStrategy(
|
|||
console.error(err);
|
||||
cb(err);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
passport.use(discordLogin);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ const facebookLogin = new FacebookStrategy(
|
|||
clientID: process.env.FACEBOOK_APP_ID,
|
||||
clientSecret: process.env.FACEBOOK_SECRET,
|
||||
callbackURL: `${domains.server}${process.env.FACEBOOK_CALLBACK_URL}`,
|
||||
proxy: true
|
||||
proxy: true,
|
||||
// profileFields: [
|
||||
// 'id',
|
||||
// 'email',
|
||||
|
|
@ -46,14 +46,14 @@ const facebookLogin = new FacebookStrategy(
|
|||
username: profile.name.givenName + profile.name.familyName,
|
||||
email: profile.emails[0].value,
|
||||
name: profile.displayName,
|
||||
avatar: profile.photos[0].value
|
||||
avatar: profile.photos[0].value,
|
||||
}).save();
|
||||
|
||||
done(null, newUser);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
passport.use(facebookLogin);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ const githubLogin = new GitHubStrategy(
|
|||
clientSecret: process.env.GITHUB_CLIENT_SECRET,
|
||||
callbackURL: `${domains.server}${process.env.GITHUB_CALLBACK_URL}`,
|
||||
proxy: false,
|
||||
scope: ['user:email'] // Request email scope
|
||||
scope: ['user:email'], // Request email scope
|
||||
},
|
||||
async (accessToken, refreshToken, profile, cb) => {
|
||||
try {
|
||||
|
|
@ -33,7 +33,7 @@ const githubLogin = new GitHubStrategy(
|
|||
email,
|
||||
emailVerified: profile.emails[0].verified,
|
||||
name: profile.displayName,
|
||||
avatar: profile.photos[0].value
|
||||
avatar: profile.photos[0].value,
|
||||
}).save();
|
||||
|
||||
cb(null, newUser);
|
||||
|
|
@ -41,7 +41,7 @@ const githubLogin = new GitHubStrategy(
|
|||
console.error(err);
|
||||
cb(err);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
passport.use(githubLogin);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ const googleLogin = new GoogleStrategy(
|
|||
clientID: process.env.GOOGLE_CLIENT_ID,
|
||||
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
|
||||
callbackURL: `${domains.server}${process.env.GOOGLE_CALLBACK_URL}`,
|
||||
proxy: true
|
||||
proxy: true,
|
||||
},
|
||||
async (accessToken, refreshToken, profile, cb) => {
|
||||
try {
|
||||
|
|
@ -31,13 +31,13 @@ const googleLogin = new GoogleStrategy(
|
|||
email: profile.emails[0].value,
|
||||
emailVerified: profile.emails[0].verified,
|
||||
name: `${profile.name.givenName} ${profile.name.familyName}`,
|
||||
avatar: profile.photos[0].value
|
||||
avatar: profile.photos[0].value,
|
||||
}).save();
|
||||
cb(null, newUser);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
passport.use(googleLogin);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ const User = require('../models/User');
|
|||
const jwtLogin = new JwtStrategy(
|
||||
{
|
||||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||
secretOrKey: process.env.JWT_SECRET
|
||||
secretOrKey: process.env.JWT_SECRET,
|
||||
},
|
||||
async (payload, done) => {
|
||||
try {
|
||||
|
|
@ -20,7 +20,7 @@ const jwtLogin = new JwtStrategy(
|
|||
} catch (err) {
|
||||
done(err, false);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
passport.use(jwtLogin);
|
||||
|
|
|
|||
|
|
@ -10,14 +10,14 @@ const passportLogin = new PassportLocalStrategy(
|
|||
usernameField: 'email',
|
||||
passwordField: 'password',
|
||||
session: false,
|
||||
passReqToCallback: true
|
||||
passReqToCallback: true,
|
||||
},
|
||||
async (req, email, password, done) => {
|
||||
const { error } = loginSchema.validate(req.body);
|
||||
if (error) {
|
||||
log({
|
||||
title: 'Passport Local Strategy - Validation Error',
|
||||
parameters: [{ name: 'req.body', value: req.body }]
|
||||
parameters: [{ name: 'req.body', value: req.body }],
|
||||
});
|
||||
return done(null, false, { message: error.details[0].message });
|
||||
}
|
||||
|
|
@ -27,7 +27,7 @@ const passportLogin = new PassportLocalStrategy(
|
|||
if (!user) {
|
||||
log({
|
||||
title: 'Passport Local Strategy - User Not Found',
|
||||
parameters: [{ name: 'email', value: email }]
|
||||
parameters: [{ name: 'email', value: email }],
|
||||
});
|
||||
return done(null, false, { message: 'Email does not exists.' });
|
||||
}
|
||||
|
|
@ -36,14 +36,14 @@ const passportLogin = new PassportLocalStrategy(
|
|||
if (err) {
|
||||
log({
|
||||
title: 'Passport Local Strategy - Compare password error',
|
||||
parameters: [{ name: 'error', value: err }]
|
||||
parameters: [{ name: 'error', value: err }],
|
||||
});
|
||||
return done(err);
|
||||
}
|
||||
if (!isMatch) {
|
||||
log({
|
||||
title: 'Passport Local Strategy - Password does not match',
|
||||
parameters: [{ name: 'isMatch', value: isMatch }]
|
||||
parameters: [{ name: 'isMatch', value: isMatch }],
|
||||
});
|
||||
return done(null, false, { message: 'Incorrect password.' });
|
||||
}
|
||||
|
|
@ -53,7 +53,7 @@ const passportLogin = new PassportLocalStrategy(
|
|||
} catch (err) {
|
||||
return done(err);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
passport.use(passportLogin);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
const passport = require('passport');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { Issuer, Strategy: OpenIDStrategy } = require('openid-client');
|
||||
const axios = require('axios');
|
||||
const fs = require('fs');
|
||||
|
|
@ -20,11 +19,11 @@ const downloadImage = async (url, imagePath, accessToken) => {
|
|||
try {
|
||||
const response = await axios.get(url, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${accessToken}`
|
||||
'Authorization': `Bearer ${accessToken}`,
|
||||
},
|
||||
responseType: 'arraybuffer'
|
||||
responseType: 'arraybuffer',
|
||||
});
|
||||
|
||||
|
||||
fs.mkdirSync(path.dirname(imagePath), { recursive: true });
|
||||
fs.writeFileSync(imagePath, response.data);
|
||||
|
||||
|
|
@ -42,15 +41,15 @@ Issuer.discover(process.env.OPENID_ISSUER)
|
|||
const client = new issuer.Client({
|
||||
client_id: process.env.OPENID_CLIENT_ID,
|
||||
client_secret: process.env.OPENID_CLIENT_SECRET,
|
||||
redirect_uris: [domains.server + process.env.OPENID_CALLBACK_URL]
|
||||
redirect_uris: [domains.server + process.env.OPENID_CALLBACK_URL],
|
||||
});
|
||||
|
||||
const openidLogin = new OpenIDStrategy(
|
||||
{
|
||||
client,
|
||||
params: {
|
||||
scope: process.env.OPENID_SCOPE
|
||||
}
|
||||
scope: process.env.OPENID_SCOPE,
|
||||
},
|
||||
},
|
||||
async (tokenset, userinfo, done) => {
|
||||
try {
|
||||
|
|
@ -68,7 +67,7 @@ Issuer.discover(process.env.OPENID_ISSUER)
|
|||
} else if (userinfo.family_name) {
|
||||
fullName = userinfo.family_name;
|
||||
}
|
||||
|
||||
|
||||
if (!user) {
|
||||
user = new User({
|
||||
provider: 'openid',
|
||||
|
|
@ -76,7 +75,7 @@ Issuer.discover(process.env.OPENID_ISSUER)
|
|||
username: userinfo.given_name || '',
|
||||
email: userinfo.email || '',
|
||||
emailVerified: userinfo.email_verified || false,
|
||||
name: fullName
|
||||
name: fullName,
|
||||
});
|
||||
} else {
|
||||
user.provider = 'openid';
|
||||
|
|
@ -105,14 +104,14 @@ Issuer.discover(process.env.OPENID_ISSUER)
|
|||
} else {
|
||||
user.avatar = '';
|
||||
}
|
||||
|
||||
|
||||
await user.save();
|
||||
|
||||
|
||||
done(null, user);
|
||||
} catch (err) {
|
||||
done(err);
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
passport.use('openid', openidLogin);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ const Joi = require('joi');
|
|||
|
||||
const loginSchema = Joi.object().keys({
|
||||
email: Joi.string().trim().email().required(),
|
||||
password: Joi.string().trim().min(8).max(128).required()
|
||||
password: Joi.string().trim().min(8).max(128).required(),
|
||||
});
|
||||
|
||||
const registerSchema = Joi.object().keys({
|
||||
|
|
@ -15,10 +15,10 @@ const registerSchema = Joi.object().keys({
|
|||
.required(),
|
||||
email: Joi.string().trim().email().required(),
|
||||
password: Joi.string().trim().min(8).max(128).required(),
|
||||
confirm_password: Joi.string().trim().min(8).max(128).required()
|
||||
confirm_password: Joi.string().trim().min(8).max(128).required(),
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
loginSchema,
|
||||
registerSchema
|
||||
registerSchema,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue