2023-12-30 05:56:40 -05:00
|
|
|
// import { authMiddleware } from "@clerk/nextjs";
|
|
|
|
// import { NextResponse } from "next/server";
|
|
|
|
|
|
|
|
// // This example protects all routes including api/trpc routes
|
|
|
|
// // Please edit this to allow other routes to be public as needed.
|
|
|
|
// // See https://clerk.com/docs/references/nextjs/auth-middleware for more information about configuring your middleware
|
|
|
|
// export default authMiddleware({
|
|
|
|
// publicRoutes: ["/api/:path*"],
|
|
|
|
// ignoredRoutes: ["/api/validate/:path*"],
|
|
|
|
|
|
|
|
// beforeAuth: async (req) => {
|
|
|
|
// // if (req.url.startsWith("https://localhost:3000/api") /*&& !req.url.startsWith("https://localhost:3000/api/validate/")*/) {
|
|
|
|
// // const apiKey = req.headers.get("x-api-key") as string
|
|
|
|
// // let api = null
|
|
|
|
// // if (apiKey != null) {
|
|
|
|
// // console.log("API KEY:", apiKey)
|
|
|
|
// // api = await fetch("http://localhost:3000/api/validate")
|
|
|
|
// // }
|
|
|
|
// // if (api == null) {
|
|
|
|
// // console.log("Invalid API key attempted")
|
|
|
|
// // return NextResponse.rewrite(
|
|
|
|
// // `${req.nextUrl.protocol}//${req.nextUrl.host}`,
|
|
|
|
// // {
|
|
|
|
// // status: 401,
|
|
|
|
// // headers: {
|
|
|
|
// // "WWW-Authenticate": 'Basic realm="Secure Area"',
|
|
|
|
// // },
|
|
|
|
// // }
|
|
|
|
// // );
|
|
|
|
// // }
|
|
|
|
// // }
|
|
|
|
|
|
|
|
// return NextResponse.next();
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
|
|
|
|
// export const config = {
|
|
|
|
// matcher: ["/((?!.*\\..*|_next).*)", "/", "/(trpc)(.*)"],
|
|
|
|
// };
|
|
|
|
|
|
|
|
import { NextResponse } from "next/server";
|
|
|
|
import { redirect } from 'next/navigation';
|
|
|
|
import { withAuth } from 'next-auth/middleware';
|
|
|
|
import { getServerSession } from "next-auth";
|
|
|
|
|
|
|
|
export default withAuth(
|
|
|
|
async function middleware(req) {
|
2023-12-31 05:41:55 -05:00
|
|
|
const requestHeaders = new Headers(req.headers);
|
|
|
|
requestHeaders.set('x-url', req.url);
|
2023-12-30 05:56:40 -05:00
|
|
|
|
2023-12-31 05:41:55 -05:00
|
|
|
return NextResponse.next({
|
|
|
|
request: {
|
|
|
|
// Apply new request headers
|
|
|
|
headers: requestHeaders,
|
|
|
|
}
|
|
|
|
});
|
2023-12-30 05:56:40 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
callbacks: {
|
|
|
|
authorized: async ({ req, token }) =>
|
|
|
|
req.nextUrl.pathname?.slice(0, 4) === '/api' ||
|
|
|
|
!!token
|
|
|
|
}
|
|
|
|
});
|