mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 01:10:14 +01:00
feat: facebook login (#820)
* Facebook strategy * Update user_auth_system.md * Update user_auth_system.md
This commit is contained in:
parent
a569020312
commit
007d51ede1
23 changed files with 155 additions and 27 deletions
|
|
@ -5,8 +5,7 @@ const domains = config.domains;
|
|||
|
||||
const facebookLogin = async (accessToken, refreshToken, profile, cb) => {
|
||||
try {
|
||||
console.log('facebookLogin => profile', profile);
|
||||
const email = profile.emails[0].value;
|
||||
const email = profile.emails[0]?.value;
|
||||
const facebookId = profile.id;
|
||||
const oldUser = await User.findOne({
|
||||
email,
|
||||
|
|
@ -15,17 +14,17 @@ const facebookLogin = async (accessToken, refreshToken, profile, cb) => {
|
|||
process.env.ALLOW_SOCIAL_REGISTRATION?.toLowerCase() === 'true';
|
||||
|
||||
if (oldUser) {
|
||||
oldUser.avatar = profile.photos[0].value;
|
||||
oldUser.avatar = profile.photo;
|
||||
await oldUser.save();
|
||||
return cb(null, oldUser);
|
||||
} else if (ALLOW_SOCIAL_REGISTRATION) {
|
||||
const newUser = await new User({
|
||||
provider: 'facebook',
|
||||
facebookId,
|
||||
username: profile.name.givenName + profile.name.familyName,
|
||||
username: profile.displayName,
|
||||
email,
|
||||
name: profile.displayName,
|
||||
avatar: profile.photos[0].value,
|
||||
name: profile.name?.givenName + ' ' + profile.name?.familyName,
|
||||
avatar: profile.photos[0]?.value,
|
||||
}).save();
|
||||
|
||||
return cb(null, newUser);
|
||||
|
|
@ -43,23 +42,12 @@ const facebookLogin = async (accessToken, refreshToken, profile, cb) => {
|
|||
module.exports = () =>
|
||||
new FacebookStrategy(
|
||||
{
|
||||
clientID: process.env.FACEBOOK_APP_ID,
|
||||
clientSecret: process.env.FACEBOOK_SECRET,
|
||||
clientID: process.env.FACEBOOK_CLIENT_ID,
|
||||
clientSecret: process.env.FACEBOOK_CLIENT_SECRET,
|
||||
callbackURL: `${domains.server}${process.env.FACEBOOK_CALLBACK_URL}`,
|
||||
proxy: true,
|
||||
// profileFields: [
|
||||
// 'id',
|
||||
// 'email',
|
||||
// 'gender',
|
||||
// 'profileUrl',
|
||||
// 'displayName',
|
||||
// 'locale',
|
||||
// 'name',
|
||||
// 'timezone',
|
||||
// 'updated_time',
|
||||
// 'verified',
|
||||
// 'picture.type(large)'
|
||||
// ]
|
||||
scope: ['public_profile'],
|
||||
profileFields: ['id', 'email', 'name'],
|
||||
},
|
||||
facebookLogin,
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue