file based auth

This commit is contained in:
2026-02-23 09:58:08 +00:00
parent 0bea406dcd
commit 2779fe22c6
40 changed files with 456 additions and 1010 deletions
+4 -12
View File
@@ -1,6 +1,6 @@
import type { Handler } from 'hono';
import type { User } from 'types';
import { officerdb, eq, Users } from 'officerdb';
import { getUserById, updateUser } from 'officerdb';
import { verify as verifyJwt, sign } from '@@/jwt';
import argon2 from 'argon2';
import * as errors from '@@/custom-errors';
@@ -11,9 +11,7 @@ export const verifyHandler: Handler = async function (ctx) {
const userInfo = (await verifyJwt(verificationCode)) as User;
if (!userInfo) throw errors.BAD_REQUEST();
const user = await officerdb.query.Users.findFirst({
where: eq(Users.id, userInfo.id),
});
const user = getUserById(userInfo.id);
if (!user) throw errors.NOT_FOUND('User not found');
const updates: Record<string, unknown> = { status: 'Active' };
@@ -37,16 +35,10 @@ export const verifyHandler: Handler = async function (ctx) {
updates.password = await argon2.hash(password);
}
const [updatedUser] = await officerdb
.update(Users)
.set(updates)
.where(eq(Users.id, userInfo.id))
.returning({ username: Users.username });
await updateUser(userInfo.id, updates);
// Re-fetch user to get final values after update
const finalUser = await officerdb.query.Users.findFirst({
where: eq(Users.id, userInfo.id),
});
const finalUser = getUserById(userInfo.id);
if (!finalUser) throw errors.NOT_FOUND('User not found');
// Issue a token so the user is logged in immediately