@devmoods/express-extras 0.15.1 → 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.
- package/dist/auth.js +8 -9
- package/package.json +1 -1
package/dist/auth.js
CHANGED
|
@@ -66,24 +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
|
-
|
|
70
|
-
password: { type: 'string' },
|
|
69
|
+
password: { type: 'string', minLength: 8 },
|
|
71
70
|
},
|
|
72
|
-
required: ['
|
|
71
|
+
required: ['password'],
|
|
73
72
|
}), route(async (req) => {
|
|
74
|
-
const {
|
|
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
|
|
80
|
-
|
|
81
|
-
|
|
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
84
|
await redis.del(token);
|
|
86
|
-
logger.info('user changed password', { email
|
|
85
|
+
logger.info('user changed password', { email });
|
|
87
86
|
return 200;
|
|
88
87
|
}));
|
|
89
88
|
router.get('/reset/:token', validateParams(tokenSchema), route(async (req) => {
|