fix add new withCorsMiddleware
parent
ca8ca913a8
commit
a4851bd0b6
|
@ -13,12 +13,11 @@ const today = new Date();
|
|||
|
||||
// This verifies the API key and sets the user if it is valid.
|
||||
export const verifyApiKey: NextMiddleware = async (req, res, next) => {
|
||||
const pathIsDocs = req.url?.startsWith("/docs");
|
||||
if (pathIsDocs) await next();
|
||||
else if (!req.query.apiKey) res.status(401).json({ message: "No API key provided" });
|
||||
if (!req.query.apiKey) res.status(401).json({ message: "No API key provided" });
|
||||
|
||||
const strippedApiKey = `${req.query.apiKey}`.replace(process.env.API_KEY_PREFIX || "cal_", "");
|
||||
const hashedKey = hashAPIKey(strippedApiKey);
|
||||
|
||||
await prisma.apiKey
|
||||
.findUnique({ where: { hashedKey } })
|
||||
.then(async (apiKey) => {
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
import { label } from "next-api-middleware";
|
||||
|
||||
import { withCors } from "./withCors";
|
||||
|
||||
const withCorsMiddleware = label(
|
||||
{
|
||||
withCors,
|
||||
},
|
||||
["withCors"] // <-- Provide a list of middleware to call automatically
|
||||
);
|
||||
|
||||
export { withCorsMiddleware };
|
|
@ -3,7 +3,7 @@ import pjson from "@/package.json";
|
|||
import { withSwagger } from "next-swagger-doc";
|
||||
|
||||
import { withCors } from "@lib/helpers/withCors";
|
||||
import { withMiddleware } from "@lib/helpers/withMiddleware";
|
||||
import { withCorsMiddleware } from "@lib/helpers/withCorsMiddleware";
|
||||
|
||||
const swaggerHandler = withSwagger({
|
||||
definition: {
|
||||
|
@ -19,4 +19,4 @@ const swaggerHandler = withSwagger({
|
|||
tags: ["users", "teams", "memeberships"],
|
||||
sort: true,
|
||||
});
|
||||
export default withMiddleware(withCors)(swaggerHandler());
|
||||
export default withCorsMiddleware()(swaggerHandler());
|
||||
|
|
Loading…
Reference in New Issue