apiexamples
Browse
Pricing
Docs
Have a key?
Get All-Access — $19
Browse
/
Clerk
/
Protect API Routes
Protect API Routes
Clerk
Free sample
Verify a Clerk session token in a Next.js API route.
TypeScript
route.ts
Copy
const
{
userId
}
=
auth
();
if
(!
userId
)
return
unauthorized
();
return
NextResponse
.
json
({
ok
:
true
});
Related snippets
MongoDB
TypeScript
Insert a Document
Insert a document into a MongoDB collection using the official driver.
const result = await collection.insertOne(newCustomer);
$19 · Pro
View →
MongoDB
TypeScript
Update a Document
Update a document in a MongoDB collection using the official driver.
const result = await subscribers.updateOne(filter, update);
$19 · Pro
View →
MongoDB
TypeScript
Query Documents
Query documents from a MongoDB collection with a filter using the official driver.
const cursor = orders.find(filter).sort({ createdAt: -1 }).limit(20);
$19 · Pro
View →
Protect API Routes — Clerk Example (TypeScript) | apiexamples