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
+5 -10
View File
@@ -1,24 +1,19 @@
import type { Handler } from 'hono';
import type { User } from 'types';
import * as errors from '@@/custom-errors';
import { officerdb, eq, Users, Passkeys } from 'officerdb';
import { getUserById, getPasskeysByEmailAndOrigin } from 'officerdb';
export const usersMe: Handler = async function (ctx) {
const user = ctx.get('user') as User;
const origin = ctx.get('origin') as string;
const dbUser = await officerdb.query.Users.findFirst({
where: eq(Users.id, user.id),
columns: { password: false },
with: {
passkeys: { where: eq(Passkeys.origin, origin || '') },
},
});
const dbUser = getUserById(user.id);
if (!dbUser) return errors.NOT_FOUND();
const { passkeys, ...userWithoutPasskeys } = dbUser;
const returnUser = { ...userWithoutPasskeys, passkeyCount: passkeys.length };
const passkeys = getPasskeysByEmailAndOrigin(dbUser.email, origin || '');
const { password, ...userWithoutPassword } = dbUser;
const returnUser = { ...userWithoutPassword, passkeyCount: passkeys.length };
return ctx.json(returnUser);
};