Skip to content

Commit

Permalink
Merge pull request #1183 from andrew-bierman/Fix-updatePassword
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-bierman authored Aug 24, 2024
2 parents 00fe11e + 203c3de commit 333987c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions server/src/controllers/auth/updatePassword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ import { findUserAndUpdate } from '../../services/user/user.service';
import * as validator from '@packrat/validations';
import { hashPassword } from '../../utils/user';
import { type Context } from 'hono';
import { User } from '../../drizzle/methods/User';

export const updatePassword = async (c: Context) => {
try {
const { email, password } = await c.req.json();
const JWT_SECRET = c.env.JWT_SECRET;
const hashedPassword = await hashPassword(JWT_SECRET, password);
const user = await findUserAndUpdate(email, hashedPassword, 'password');
return c.json({ user }, 200);
const currentUser = await findUserAndUpdate(
email,
hashedPassword,
'password',
);
return c.json({ currentUser }, 200);
} catch (error) {
return c.json({ error: `Email Doesnt Exist: ${error.message}` }, 404);
}
Expand All @@ -23,8 +28,17 @@ export function updatePasswordRoute() {
const { email, password } = opts.input;
const { env }: any = opts.ctx;
const JWT_SECRET = env.JWT_SECRET;
const userClass = new User();
const user = await userClass.findByCredentials(email, password);
if (!user) {
throw new Error('Password is not correct');
}
const hashedPassword = await hashPassword(JWT_SECRET, password);
const user = await findUserAndUpdate(email, hashedPassword, 'password');
return user;
const currentUser = await findUserAndUpdate(
email,
hashedPassword,
'password',
);
return currentUser;
});
}

0 comments on commit 333987c

Please sign in to comment.