Fix recorder finalize path and add invite-gated login

这个提交包含在:
cryptocommuniums-afk
2026-03-15 00:52:11 +08:00
父节点 ad83ce9c68
当前提交 d1b6603061
修改 13 个文件,包含 458 行新增18 行删除

查看文件

@@ -82,7 +82,16 @@ export async function getUserByUsername(username: string) {
return userResult.length > 0 ? userResult[0] : undefined;
}
export async function createUsernameAccount(username: string): Promise<{ user: typeof users.$inferSelect; isNew: boolean }> {
export function isValidRegistrationInvite(inviteCode?: string | null) {
const expected = ENV.registrationInviteCode.trim();
if (!expected) return true;
return (inviteCode ?? "").trim() === expected;
}
export async function createUsernameAccount(
username: string,
inviteCode?: string,
): Promise<{ user: typeof users.$inferSelect; isNew: boolean }> {
const db = await getDb();
if (!db) throw new Error("Database not available");
@@ -97,6 +106,10 @@ export async function createUsernameAccount(username: string): Promise<{ user: t
}
}
if (!isValidRegistrationInvite(inviteCode)) {
throw new Error("新用户注册需要正确的邀请码");
}
// Create new user with username as openId
const openId = `username_${username}_${Date.now()}`;
await db.insert(users).values({