Move from storing tokens in Berry Dash Database to Lncvrt Games Database

This commit is contained in:
2026-01-29 19:20:24 -07:00
parent 29b60e567f
commit 024b651c52
17 changed files with 32 additions and 64 deletions

29
src/lib/auth.ts Normal file
View File

@@ -0,0 +1,29 @@
import { MySql2Database } from 'drizzle-orm/mysql2'
import { users } from './tables'
import { eq } from 'drizzle-orm'
export async function checkAuthorization (
authorizationToken: string,
db0: MySql2Database,
updateIp: string | null
) {
if (!authorizationToken) return { valid: false, id: 0 }
const userData = await db0
.select({ id: users.id })
.from(users)
.where(eq(users.token, authorizationToken))
.execute()
if (!userData[0]) return { valid: false, id: 0 }
else {
if (updateIp != undefined && updateIp != null && db0 != undefined)
db0
.update(users)
.set({ latestIp: updateIp })
.where(eq(users.id, userData[0].id))
.execute()
return { valid: true, id: userData[0].id }
}
}