Make a auth lib for Berry Dash

This commit is contained in:
2026-01-21 16:13:08 -07:00
parent d842e25b4e
commit 291f2f64d2
5 changed files with 76 additions and 107 deletions

19
src/lib/bd/auth.ts Normal file
View File

@@ -0,0 +1,19 @@
import { MySql2Database } from 'drizzle-orm/mysql2'
import { berryDashUserData } from '../tables'
import { eq } from 'drizzle-orm'
export async function checkAuthorization (
authorizationToken: string,
db1: MySql2Database
) {
if (!authorizationToken) return { valid: false, id: 0 }
const userData = await db1
.select({ id: berryDashUserData.id })
.from(berryDashUserData)
.where(eq(berryDashUserData.token, authorizationToken))
.execute()
if (!userData[0]) return { valid: false, id: 0 }
else return { valid: true, id: userData[0].id }
}