You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 29, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Jul 29, 2026. It is now read-only.
Inserting new record on every login. issue not fixed yet server:oauth mongoose validation when re-login using twitter oauth #1851 #1883
if (authTypes.indexOf(this.provider) !== -1) {
return respond(true);
}
in user.model it remove that error
ValidationError: The specified email address is already in use.
at MongooseError.ValidationError (xxx/node_modules/mongoose/lib/error/validation.js:22:11)
at model.Document.invalidate (xxx/node_modules/mongoose/lib/document.js:1347:32)
at xxx/node_modules/mongoose/lib/document.js:1214:17
at validate (xxx/node_modules/mongoose/lib/schematype.js:693:7)
at xxx/node_modules/mongoose/lib/schematype.js:721:11
at user.model.js:122:18
From previous event:
at model.wrappedPointCut [as save] (xxx/node_modules/mongoose/lib/document.js:1828:14)
at passport.js:30:16
at processImmediate [as _immediateCallback] (timers.js:383:17)
From previous event:
at Strategy._verify (passport.js:12:10)
at xxx/node_modules/passport-oauth2/lib/strategy.js:193:24
at xxx/node_modules/passport-github2/lib/strategy.js:121:14
at passBackControl (xxx/node_modules/oauth/lib/oauth2.js:125:9)
at IncomingMessage.<anonymous> (xxx/node_modules/oauth/lib/oauth2.js:143:7)
at emitNone (events.js:85:20)
at IncomingMessage.emit (events.js:179:7)
at endReadableNT (_stream_readable.js:913:12)
at _combinedTickCallback (node.js:377:13)
at process._tickCallback (node.js:401:11)
validationerror: The specified email address is already in use.
at MongooseError.ValidationError (xxx/node_modules/mongoose/lib/error/validation.js:22:11)
at model.Document.invalidate (xxx/node_modules/mongoose/lib/document.js:1347:32)
at xxx/node_modules/mongoose/lib/document.js:1214:17
at validate (xxx/node_modules/mongoose/lib/schematype.js:693:7)
at xxx/node_modules/mongoose/lib/schematype.js:721:11
at user.model.js:122:18
From previous event: at model.wrappedPointCut [as save] (xxx/node_modules/mongoose/lib/document.js:1828:14)
at passport.js:30:16
at processImmediate [as _immediateCallback] (timers.js:383:17)From previous event:
at Strategy._verify (passport.js:12:10)
at xxx/node_modules/passport-oauth2/lib/strategy.js:193:24
at xxx/node_modules/passport-github2/lib/strategy.js:121:14
at passBackControl (xxx/node_modules/oauth/lib/oauth2.js:125:9)
at IncomingMessage.<anonymous> (xxx/node_modules/oauth/lib/oauth2.js:143:7)
at emitNone (events.js:85:20) at IncomingMessage.emit (events.js:179:7)
at endReadableNT (_stream_readable.js:913:12)
at _combinedTickCallback (node.js:377:13)
at process._tickCallback (node.js:401:11)
but it stores another record in database so this will populate my db on every twitter login with a new record.
So that bit of code you mentioned was recently added to the generator to address that issue of twitter not giving an email address, but what's happening now is that every time someone logs in with twitter it will create a new user? That's the point of this line; it checks if there's already a user with that twitter ID. Do you know why that check wouldn't pass?
parseInt parses strings to numbers, so if it was already a number that wouldn't change anything.
We want to make sure that the ID is saved as a string. In the beginning of the twitter passport setup, try making sure that profile.id && profile.__json.id are strings and if not, convert them to strings.
Activity
Awk34 commentedon Jun 16, 2016
Is this because you're not getting an email back from the twitter oauth response? You might want to add logic to not require an email..waqas19921 commentedon Jun 16, 2016
Twitter does not give email in response
waqas19921 commentedon Jun 16, 2016
Kindly check twitter response first than remove check.
Awk34 commentedon Jun 16, 2016
So that bit of code you mentioned was recently added to the generator to address that issue of twitter not giving an email address, but what's happening now is that every time someone logs in with twitter it will create a new user? That's the point of this line; it checks if there's already a user with that twitter ID. Do you know why that check wouldn't pass?
waqas19921 commentedon Jun 16, 2016
that check wouldn't pass because twitter id is saved as Int32 in mongo while that line in passport performs string matching.
waqas19921 commentedon Jun 16, 2016
thats why i have used parseInt
Awk34 commentedon Jun 16, 2016
parseIntparses strings to numbers, so if it was already a number that wouldn't change anything.We want to make sure that the ID is saved as a string. In the beginning of the twitter passport setup, try making sure that
profile.id&&profile.__json.idare strings and if not, convert them to strings.waqas19921 commentedon Jun 17, 2016
Ok that can also be done.
Save profile.id as string than no need of parseInt