Skip to content

Inserting new record on every login. issue not fixed yet server:oauth mongoose validation when re-login using twitter oauth #1851 #1883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
waqas19921 opened this issue May 14, 2016 · 8 comments

Comments

@waqas19921
Copy link

When i added that line

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.

@Awk34
Copy link
Member

Awk34 commented 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
Copy link
Author

Twitter does not give email in response

@waqas19921
Copy link
Author

Kindly check twitter response first than remove check.

@Awk34
Copy link
Member

Awk34 commented 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
Copy link
Author

waqas19921 commented 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
Copy link
Author

thats why i have used parseInt

@Awk34
Copy link
Member

Awk34 commented Jun 16, 2016

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.

@waqas19921
Copy link
Author

Ok that can also be done.
Save profile.id as string than no need of parseInt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants