Clerk logo

Clerk Docs

Ctrl + K
Go to clerk.devGet API keys

Handling requests with Gatsby

Gatsby Functions

Gatsby Functions provides an Express-like architecture that simplifies building Node.js APIs.

So, Gatsby Functions can use the ClerkExpressWithAuth and ClerkExpressRequireAuth middlewares from the Clerk Node SDK as shown below.

import { ClerkExpressRequireAuth } from '@clerk/clerk-sdk-node';
const requireAuth = ClerkExpressRequireAuth();
export default async function clerkHandler(req, res) {
await new Promise((resolve, reject) => {
requireAuth(req, res, result => {
if (result instanceof Error) {
reject(result);
}
resolve(result);
});
})
res.json(`Hi from Gatsby Functions`)
}

Was this helpful?

Clerk © 2022