Add an option to checkAuth to update the user's latest IP
This commit is contained in:
@@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user