mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-08-16 00:40:19 +02:00
fix: fix user connection
This commit is contained in:
+2
-2
@@ -72,7 +72,7 @@ async function connect(db) {
|
|||||||
github: r.profile.id,
|
github: r.profile.id,
|
||||||
},
|
},
|
||||||
username: r.username,
|
username: r.username,
|
||||||
emails: r.profile.emails.map((email) => {
|
emails: r.profile.emails?.map((email) => {
|
||||||
return { email: email.value, default: false };
|
return { email: email.value, default: false };
|
||||||
}),
|
}),
|
||||||
photo: r.profile.photos[0]?.value,
|
photo: r.profile.photos[0]?.value,
|
||||||
@@ -82,7 +82,7 @@ async function connect(db) {
|
|||||||
options: r.default.options,
|
options: r.default.options,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (user.emails.length) user.emails[0].default = true;
|
if (user.emails?.length) user.emails[0].default = true;
|
||||||
|
|
||||||
await user.save();
|
await user.save();
|
||||||
|
|
||||||
|
|||||||
+12
-10
@@ -32,21 +32,23 @@ const verify = async (
|
|||||||
let user: IUserDocument;
|
let user: IUserDocument;
|
||||||
try {
|
try {
|
||||||
user = await UserModel.findOne({ "externalIDs.github": profile.id });
|
user = await UserModel.findOne({ "externalIDs.github": profile.id });
|
||||||
const email = profile.emails ? profile.emails[0]?.value : null;
|
|
||||||
const photo = profile.photos ? profile.photos[0]?.value : null;
|
|
||||||
if (user) {
|
if (user) {
|
||||||
user.accessToken = accessToken;
|
user.accessTokens.github = accessToken;
|
||||||
user.email = photo;
|
|
||||||
user.photo = photo;
|
|
||||||
await user.save();
|
|
||||||
} else {
|
} else {
|
||||||
user = await new UserModel({
|
const photo = profile.photos ? profile.photos[0]?.value : null;
|
||||||
|
user = new UserModel({
|
||||||
username: profile.username,
|
username: profile.username,
|
||||||
accessToken: accessToken,
|
accessTokens: {
|
||||||
email,
|
github: accessToken,
|
||||||
|
},
|
||||||
|
emails: profile.emails?.map((email) => {
|
||||||
|
return { email: email.value, default: false };
|
||||||
|
}),
|
||||||
photo,
|
photo,
|
||||||
}).save();
|
});
|
||||||
|
if (user.emails?.length) user.emails[0].default = true;
|
||||||
}
|
}
|
||||||
|
await user.save();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user