Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(examples): Updated to Clerk Core 2 (Clerk NextJS v5) #704

Merged
merged 3 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading