Actually set type and userId for codes, don't know what I was thinking

This commit is contained in:
2026-01-23 20:58:00 -07:00
parent ceace4ad8c
commit 4de12cc077
3 changed files with 14 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
import {
bigint,
boolean,
int,
longtext,
mysqlTable,
text,
@@ -77,11 +78,13 @@ export const verifyCodes = mysqlTable('verifycodes', {
export const resetCodes = mysqlTable('resetcodes', {
id: bigint('id', { mode: 'number' }).primaryKey().autoincrement().notNull(),
code: varchar('code', { length: 64 }).notNull(),
userId: bigint('userId', { mode: 'number' }).notNull(),
ip: varchar('ip', { length: 255 }),
timestamp: bigint('timestamp', { mode: 'number' }).notNull(),
usedTimestamp: bigint('usedTimestamp', { mode: 'number' })
.default(0)
.notNull()
.notNull(),
type: int('type').notNull()
})
// berrydashdatabase

View File

@@ -117,9 +117,11 @@ export async function handler (context: Context) {
.from(resetCodes)
.where(
and(
eq(resetCodes.userId, result[0].id),
eq(resetCodes.ip, ip),
eq(resetCodes.usedTimestamp, 0),
sql`${resetCodes.timestamp} >= UNIX_TIMESTAMP() - 600`
sql`${resetCodes.timestamp} >= UNIX_TIMESTAMP() - 600`,
eq(resetCodes.type, 0)
)
)
.orderBy(desc(resetCodes.id))
@@ -128,7 +130,9 @@ export async function handler (context: Context) {
if (resetCodeExists[0]) {
code = resetCodeExists[0].code
} else {
await db0.insert(resetCodes).values({ code, ip, timestamp: time })
await db0
.insert(resetCodes)
.values({ code, userId: result[0].id, ip, timestamp: time, type: 0 })
}
sendEmail(