Registration and server authentification

This commit is contained in:
2023-03-03 16:08:50 +01:00
parent eac66702de
commit 9a677511e5
10 changed files with 238 additions and 58 deletions
+32
View File
@@ -37,6 +37,38 @@ export async function FindServer({ name }: { name: string }) {
.where('server.name', '=', name)
.executeTakeFirst()
}
export async function CreateServer({
name,
description
}: {
name: string
description: string
}) {
return await db
.insertInto('server')
.values({ name, description })
.returning(['id', 'token'])
.executeTakeFirstOrThrow()
}
//tokens are stored in raw... maybe we should use something better in the future
//Using callback for express-basic-auth
export function CheckServerToken(
this: { body: any },
name: string,
password: string,
cb: (error: Error | null, success: boolean) => void
) {
db.selectFrom('server')
.where('id', '=', Number(name))
.where('token', '=', password)
.executeTakeFirst()
.then((result) => {
if (!!result) this.body.serverId = name
cb(null, !!result)
})
}
/*
async function demo() {
const { id } = await db