Skip to content

Commit

Permalink
docs(examples): Updated to Clerk Core 2 (Clerk NextJS v5) (#704)
Browse files Browse the repository at this point in the history
Updates the Clerk examples following https://clerk.com/docs/upgrade-guides/core-2/overview
  • Loading branch information
davidmytton authored May 10, 2024
1 parent 0cafdbe commit 9049bad
Show file tree
Hide file tree
Showing 9 changed files with 1,357 additions and 1,763 deletions.
6 changes: 1 addition & 5 deletions examples/nextjs-14-clerk-rl/app/api/arcjet/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import arcjet, { ArcjetDecision, tokenBucket, detectBot, shield } from "@arcjet/next";
import { NextResponse } from "next/server";
import { currentUser } from "@clerk/nextjs";
import { currentUser } from "@clerk/nextjs/server";

// The root Arcjet client is created outside of the handler.
const aj = arcjet({
Expand All @@ -9,10 +9,6 @@ const aj = arcjet({
shield({
mode: "LIVE", // will block requests. Use "DRY_RUN" to log only
}),
detectBot({
mode: "LIVE", // will block requests. Use "DRY_RUN" to log only
block: ["AUTOMATED"], // blocks all automated clients
}),
],
});

Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs-14-clerk-rl/app/api/token/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This retrieves the Clerk JWT token for the current user so you can test the
* private API route.
*/
import { auth } from "@clerk/nextjs";
import { auth } from "@clerk/nextjs/server";

export async function GET(req: Request) {
const { userId, getToken } = auth();
Expand Down
17 changes: 11 additions & 6 deletions examples/nextjs-14-clerk-rl/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { authMiddleware } from "@clerk/nextjs";
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server";
import { NextResponse } from "next/server";

export default authMiddleware({
// Routes that can be accessed while signed out
publicRoutes: ["/", '/api/public'],
apiRoutes: ["/api/private"],
const isProtectedRoute = createRouteMatcher(["/api/private", "/api/token"]);

export default clerkMiddleware((auth, request) => {
if (isProtectedRoute(request)) {
auth().protect();
}

return NextResponse.next();
});

export const config = {
// Protects all routes, including api/trpc.
// See https://clerk.com/docs/references/nextjs/auth-middleware
// See https://clerk.com/docs/references/nextjs/clerk-middleware
// for more information about configuring your Middleware
matcher: ["/((?!.+\\.[\\w]+$|_next).*)", "/", "/(api|trpc)(.*)"],
};
Loading

0 comments on commit 9049bad

Please sign in to comment.