@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.
- package/dist/auth.js +11 -11
- 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
|
-
|
|
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
|
-
|
|
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);
|
|
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
|
-
|
|
159
|
+
logger.error(error);
|
|
160
160
|
next(Unauthorized('Invalid token'));
|
|
161
161
|
return;
|
|
162
162
|
}
|