feat: refactor reset password mutation with the REST API endpoint

This commit is contained in:
kasia.oczkowska
2024-07-17 15:04:15 +01:00
parent 27610c002c
commit dd0a1328e8
8 changed files with 45 additions and 57 deletions

View File

@@ -1,23 +0,0 @@
import User from '../../models/user.js';
const resetPassword = async (_parent, params) => {
const { token, password } = params.input;
if (!token) {
throw new Error('Reset password token is required!');
}
const user = await User.query().findOne({ reset_password_token: token });
if (!user || !user.isResetPasswordTokenValid()) {
throw new Error(
'Reset password link is not valid or expired. Try generating a new link.'
);
}
await user.resetPassword(password);
return true;
};
export default resetPassword;