Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 3626
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 2, 20222022-06-02T21:07:58+00:00 2022-06-02T21:07:58+00:00

mongodb – Javascript ES6 spread transformation changing Promise return content in Nest JS auth example

  • 0

[ad_1]

I’m using some of the NestJS sample repo 19-auth-jwt to implement an authentication system. But I’m facing a bug.

In the provider for the auth module (auth.services.ts), the method validateUser() uses JS ES6 syntax to remove the password from the user before returning it, as explained in the docs.

  async validateUser(username: string, pass: string): Promise<any> {
    const user = await this.usersService.findOne(username);
    if (user && user.password === pass) {
      const { password, ...result } = user;
      return result;
    }
    return null;
  }

This is not working for me, result looks like this:

{
  '$__': InternalCache {
    activePaths: StateMachine {
      paths: [Object],
      states: [Object],
      stateNames: [Array]
    },
    skipId: true,
    strictMode: true,
    selected: {},
    fields: {},
    exclude: null
  },
  '$isNew': false,
  _doc: {
    _id: new ObjectId("6299077a1c8989d6bdc3cb34"),
    first_name: 'Test',
    email: '[email protected]',
    password: '$2b$10$/ndkmG7qLh8RReko7TvsPOC15xd.mVDUY9mC3SVbkVndgZlVDzU4.',
    __v: 0
  }
}

Not only has it not removed the password but also it is creating a bizarre data structure which means I can’t get the user data which I then need to pass in my JWT without changing the code to access the _doc.

If I just return user instead it works (but obviously doesn’t remove the password).

My questions are:

  1. Why is this happening? My best guess is this is something to do with promises but don’t know.
  2. Should I be concerned about not removing the password if it is well protected? Note that I’m not actually returning it, this request only returns the JWT which holds the user _id, no more data.
  3. If it is a concern, what can I do about it?
  4. Is this a bug or my mistake?

I’m using MongoDB and mongoose as you might be able to tell. I’m new to Nest btw.

Reference to the code line where this is happening.

Thank you!

[ad_2]

  • 0 0 Answers
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 8056 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 1842 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 1924 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.