Clerk SDK for serverless and edge environments.
This package is a wrapper around Clerk core capabilities with added functionality and helpers aimed towards different edge and serverless platforms.
Installing the package:
npm install @clerk/edge
# or
yarn add @clerk/edge
Methods for supported platforms can be imported from the specific path:
import { withAuth } from '@clerk/edge/vercel-edge';
async function handler(req, event) {
// ...
}
export const middleware = withAuth(handler);
Currently supported environments/platforms:
To use with Edge Functions :
import { withAuth } from '@clerk/edge/vercel-edge';
async function handler(req, event) {
// ...
}
export const middleware = withAuth(handler);
Supported methods:
withAuth
verifySessionToken
- Resources API through
ClerkAPI
Clerk's JWT session token, contains the azp claim, which equals the Origin of the request during token generation. You can provide the middlewares with a list of whitelisted origins to verify against, to protect your application of the subdomain cookie leaking attack. You can find an example below:
import { withAuth } from '@clerk/edge/vercel-edge';
const authorizedParties = ['http://localhost:3000', 'https://example.com'];
async function handler(req, event) {
// ...
}
export const middleware = withAuth(handler, { authorizedParties });