-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
using custom header for zeplo to pass clerk authentication
- Loading branch information
1 parent
773a4fb
commit 1583dc2
Showing
4 changed files
with
38 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,37 @@ | ||
import { authMiddleware } from "@clerk/nextjs"; | ||
export default authMiddleware({ | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import { NextFetchEvent } from "next/server"; | ||
|
||
// This is your original middleware | ||
const clerkMiddleware = authMiddleware({ | ||
// "/" will be accessible to all users | ||
publicRoutes: ["/"], | ||
}); | ||
|
||
export async function middleware(req: NextRequest, event: NextFetchEvent) { | ||
console.log("got into middleware"); | ||
// Check if the request is from Zeplo | ||
if (req.headers.get("x-zeplo-secret") === process.env.ZEPLO_SECRET) { | ||
// Handle the request without Clerk's authMiddleware | ||
console.log("got into if"); | ||
// handleRequest(req, res); | ||
} else { | ||
console.log("got into else of middleware"); | ||
// If not from Zeplo, use Clerk's authMiddleware | ||
// const nextReq = new NextRequest(req); | ||
// const nextFetchEvent = new NextFetchEvent(req); | ||
return clerkMiddleware(req, event); | ||
} | ||
} | ||
|
||
function handleRequest(req: NextRequest, res: NextResponse) { | ||
// If you have a specific endpoint function, you can call it here. | ||
// For example, if you have an endpoint function called 'endpointFunction': | ||
// endpointFunction(req, res); | ||
// If you don't have a specific function and just want to let the request meet the endpoint, you can do nothing here. | ||
// The request will continue to the next middleware or the route handler. | ||
} | ||
|
||
export const config = { | ||
matcher: ["/((?!.*\\..*|_next).*)", "/", "/(api|trpc)(.*)"], | ||
}; |