Skip to content
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

How to change user password from client ? #28

Closed
AlenKelemen opened this issue Jun 12, 2020 · 2 comments
Closed

How to change user password from client ? #28

AlenKelemen opened this issue Jun 12, 2020 · 2 comments

Comments

@AlenKelemen
Copy link

AlenKelemen commented Jun 12, 2020

Code for this is in TODO comment, am I right ?
from code:

/**

  • Patch and Put user
    */
    // TODO: create new access token when password or email changes
@eggn
Copy link

eggn commented Jun 28, 2020

PATCH or PUT /users/:id does not encrypting the password. I think that is a bug.
As workaround I have used the follow middleware in my json server:
//Middleware for encrypt the password
server.use((req, res, next) => {
if (req.url.indexOf('users') != -1 &&
req.method === 'PATCH' || req.method === 'PUT' &&
req.body.password) {
bcrypt
.hash(req.body.password, 10)
.then((hash) => {
req.body.password = hash
next()
})
.catch(next)
}else{
next() // Simply continue with json-server router
return
}
})

@jeremyben
Copy link
Owner

Fixed in 2.1.0 with 4382ef1

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

No branches or pull requests

3 participants