@devmoods/express-extras 0.15.0 → 0.15.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/auth.js +11 -11
  2. package/package.json +1 -1
package/dist/auth.js CHANGED
@@ -39,7 +39,7 @@ export function createAuth({ getUserByToken, methods: { emailAndPassword }, filt
39
39
  return [201, { token }];
40
40
  }
41
41
  catch (error) {
42
- getLogger('core').error(error);
42
+ logger.error(error);
43
43
  throw Unauthorized(error.message);
44
44
  }
45
45
  }));
@@ -66,23 +66,23 @@ export function createAuth({ getUserByToken, methods: { emailAndPassword }, filt
66
66
  router.post('/reset/:token', validateParams(tokenSchema), validateBody({
67
67
  type: 'object',
68
68
  properties: {
69
- email: emailSchema,
70
- password: { type: 'string' },
69
+ password: { type: 'string', minLength: 8 },
71
70
  },
72
- required: ['email', 'password'],
71
+ required: ['password'],
73
72
  }), route(async (req) => {
74
- const { email, password } = req.body;
73
+ const { password } = req.body;
75
74
  const { token } = req.params;
76
75
  if (!emailAndPassword) {
77
76
  throw new Error('Not applicable for login method');
78
77
  }
79
- const user = await emailAndPassword(email, skipPasswordCheck);
80
- const tokenEmail = await redis.get(token);
81
- if (!tokenEmail || email !== tokenEmail) {
82
- throw BadRequest('invalid email');
78
+ const email = await redis.get(token);
79
+ if (!email) {
80
+ throw BadRequest('invalid reset token');
83
81
  }
82
+ const user = await emailAndPassword(email, skipPasswordCheck);
84
83
  await onPasswordChanged?.(user, await hashPassword(password));
85
- logger.info('user changed password', { email: tokenEmail });
84
+ await redis.del(token);
85
+ logger.info('user changed password', { email });
86
86
  return 200;
87
87
  }));
88
88
  router.get('/reset/:token', validateParams(tokenSchema), route(async (req) => {
@@ -156,7 +156,7 @@ export function createAuth({ getUserByToken, methods: { emailAndPassword }, filt
156
156
  next();
157
157
  }
158
158
  catch (error) {
159
- getLogger('core').error(error);
159
+ logger.error(error);
160
160
  next(Unauthorized('Invalid token'));
161
161
  return;
162
162
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devmoods/express-extras",
3
- "version": "0.15.0",
3
+ "version": "0.15.2",
4
4
  "description": "Kubernetes-ready utilities for rapid Node.js application development",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",