Skip to content

Commit cf0f88a

Browse files
committed
attempt to fix double oauth users in mongodb bu removing unique constraints in github and google ids because they were being null
1 parent 09105b7 commit cf0f88a

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

server/routers/passport-setup.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ passport.use(
3333
callbackURL: `${API_BASE_URL}/auth/github/callback`,
3434
proxy: true
3535
},
36-
function (accessToken, refreshToken, profile, done) {
36+
(accessToken, refreshToken, profile, done) => {
3737
user
3838
.findOne({
3939
githubId: profile.id
@@ -42,22 +42,27 @@ passport.use(
4242
if (currentUser) {
4343
console.log('user is: ', currentUser);
4444
return done(null, currentUser);
45+
}
46+
let initials;
47+
if (profile.displayName) {
48+
initials = profile.displayName.match(/\b\w/g).join('');
4549
} else {
46-
const initials = profile.displayName.match(/\b\w/g).join('');
47-
const nums = profile.id.slice(0, 5);
48-
user
49-
.create({
50-
username: initials + nums + '(Github)',
51-
githubId: profile.id
52-
})
53-
.then((data) => {
54-
console.log('user added successfully: ', data);
55-
return done(null, data);
56-
})
57-
.catch((data) =>
58-
console.log('issue with adding user to database', data)
59-
);
50+
initials = profile._json.login.match(/\b\w/g).join('');
6051
}
52+
53+
const nums = profile.id.slice(0, 5);
54+
user
55+
.create({
56+
username: initials + nums + '(Github)',
57+
githubId: profile.id
58+
})
59+
.then((data) => {
60+
console.log('user added successfully: ', data);
61+
return done(null, data);
62+
})
63+
.catch((data) =>
64+
console.log('issue with adding user to database', data)
65+
);
6166
});
6267
}
6368
)

0 commit comments

Comments
 (0)