Add an option to checkAuth to update the user's latest IP

This commit is contained in:
2026-01-22 18:31:48 -07:00
parent c62d4033d5
commit b4a9d26d0f
9 changed files with 104 additions and 23 deletions

View File

@@ -1,10 +1,12 @@
import { MySql2Database } from 'drizzle-orm/mysql2'
import { berryDashUserData } from '../tables'
import { berryDashUserData, users } from '../tables'
import { eq } from 'drizzle-orm'
export async function checkAuthorization (
authorizationToken: string,
db1: MySql2Database
db1: MySql2Database,
db0?: MySql2Database,
updateIp?: string | null
) {
if (!authorizationToken) return { valid: false, id: 0 }
@@ -15,5 +17,14 @@ export async function checkAuthorization (
.execute()
if (!userData[0]) return { valid: false, id: 0 }
else return { valid: true, id: userData[0].id }
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 }
}
}