fixed members login and permissions issues

This commit is contained in:
2026-02-23 00:57:34 +00:00
parent ed0debfeac
commit 97da2e2736
42 changed files with 574 additions and 113 deletions
+23 -3
View File
@@ -7,7 +7,7 @@ import * as errors from '@@/custom-errors';
import { validatePassword } from './validate-password';
export const verifyHandler: Handler = async function (ctx) {
const { verificationCode, name, password, confirmPassword } = ctx.get('body');
const { verificationCode, name, username, password, confirmPassword } = ctx.get('body');
const userInfo = (await verifyJwt(verificationCode)) as User;
if (!userInfo) throw errors.BAD_REQUEST();
@@ -25,6 +25,10 @@ export const verifyHandler: Handler = async function (ctx) {
updates.name = name.trim();
}
if (username && typeof username === 'string' && username.trim()) {
updates.username = username.trim();
}
if (password) {
validatePassword(password);
if (password !== confirmPassword) {
@@ -33,10 +37,26 @@ export const verifyHandler: Handler = async function (ctx) {
updates.password = await argon2.hash(password);
}
await officerdb.update(Users).set(updates).where(eq(Users.id, userInfo.id));
const [updatedUser] = await officerdb
.update(Users)
.set(updates)
.where(eq(Users.id, userInfo.id))
.returning({ username: Users.username });
// Re-fetch user to get final values after update
const finalUser = await officerdb.query.Users.findFirst({
where: eq(Users.id, userInfo.id),
});
if (!finalUser) throw errors.NOT_FOUND('User not found');
// Issue a token so the user is logged in immediately
const token = await sign({ id: userInfo.id, email: userInfo.email });
const token = await sign({
id: finalUser.id,
email: finalUser.email,
name: finalUser.name,
username: finalUser.username,
role: finalUser.role,
});
return ctx.json({ ok: true, token });
};