first
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import type { User } from 'types';
|
||||
import type { Handler } from 'hono';
|
||||
import { officerdb, eq, Users } from 'officerdb';
|
||||
import { verify } from '@@/jwt';
|
||||
import argon2 from 'argon2';
|
||||
import * as errors from '@@/custom-errors';
|
||||
import { validatePassword } from './validate-password';
|
||||
|
||||
export const resetPasswordHandler: Handler = async function (ctx) {
|
||||
const now = Date.now().valueOf();
|
||||
const { password, verificationCode } = ctx.get('body');
|
||||
validatePassword(password);
|
||||
const userInfo = (await verify(verificationCode)) as User;
|
||||
if (!userInfo) throw errors.UNAUTHORIZED();
|
||||
const passwordHash = await argon2.hash(password);
|
||||
await officerdb
|
||||
.update(Users)
|
||||
.set({ password: passwordHash, status: 'Active', passwordChangedAt: now })
|
||||
.where(eq(Users.id, userInfo.id));
|
||||
|
||||
return ctx.json({ ok: true });
|
||||
};
|
||||
Reference in New Issue
Block a user