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,7 +1,7 @@
import type { Handler } from 'hono';
import { officerdb, count, Users } from 'officerdb';
import { getUserCount, createUser } from 'officerdb';
import { sign } from '@@/jwt';
import { USER_ROLES, USER_STATUSES } from 'definitions';
import type { USER_ROLES, USER_STATUSES } from 'definitions';
import * as errors from '@@/custom-errors';
import { sendMail } from 'emailer';
@@ -13,19 +13,14 @@ export const signupHandler: Handler = async function (ctx) {
throw errors.BAD_REQUEST('Invalid email address');
}
const result = await officerdb.select({ count: count() }).from(Users);
const userCount = result[0]?.count ?? 0;
const userCount = getUserCount();
if (userCount > 0) throw errors.FORBIDDEN('Registration is closed');
const newUser = {
const dbUser = await createUser({
email: body.email as string,
status: 'Unverified' as (typeof USER_STATUSES)[number],
role: 'Admin' as (typeof USER_ROLES)[number],
};
const insertedUsers = await officerdb.insert(Users).values(newUser).returning();
if (!insertedUsers || insertedUsers.length === 0) throw errors.INTERNAL_SERVER_ERROR('Failed to create user');
const dbUser = insertedUsers[0]!;
});
const verificationCode = await sign({ id: dbUser.id, email: dbUser.email }, '24h');
const url = `${origin}/auth/verify?verificationCode=${verificationCode}`;