Skip to content
This repository was archived by the owner on Jul 29, 2026. It is now read-only.
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

Closed

Description

@waqas19921

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.

Activity

  1. Awk34 commented on Jun 16, 2016

    @Awk34
    Collaborator

    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..

  2. waqas19921 commented on Jun 16, 2016

    @waqas19921
    Author

    Twitter does not give email in response

  3. waqas19921 commented on Jun 16, 2016

    @waqas19921
    Author

    Kindly check twitter response first than remove check.

  4. Awk34 commented on Jun 16, 2016

    @Awk34
    Collaborator

    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?

  5. waqas19921 commented on Jun 16, 2016

    @waqas19921
    Author

    that check wouldn't pass because twitter id is saved as Int32 in mongo while that line in passport performs string matching.

  6. waqas19921 commented on Jun 16, 2016

    @waqas19921
    Author

    thats why i have used parseInt

  7. Awk34 commented on Jun 16, 2016

    @Awk34
    Collaborator

    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.

  8. waqas19921 commented on Jun 17, 2016

    @waqas19921
    Author

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

  9. added this to the Soon milestone on Jun 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions