file based auth
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user