This commit is contained in:
Carl-Gerhard Lindesvärd
2023-10-11 12:34:35 +02:00
commit 903fd155c3
40 changed files with 1385 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
import { NextFunction, Request, Response } from "express"
import { db } from "../db"
import { verifyPassword } from "../services/password"
export async function authMiddleware(req: Request, res: Response, next: NextFunction) {
const secret = req.headers['mixan-client-secret'] as string | undefined
if(!secret) {
return res.status(401).json({
code: 'UNAUTHORIZED',
message: 'Missing client secret',
})
}
const client = await db.client.findFirst({
where: {
secret,
},
})
if(!client) {
return res.status(401).json({
code: 'UNAUTHORIZED',
message: 'Invalid client secret',
})
}
req.client = {
project_id: client.project_id,
}
next()
}