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