Clerk logo

Clerk Docs

Ctrl + K
Go to clerkstage.dev
Check out a preview of our new docs.

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.

1
import { ClerkExpressRequireAuth } from '@clerk/clerk-sdk-node';
2
3
const requireAuth = ClerkExpressRequireAuth();
4
5
export default async function clerkHandler(req, res) {
6
await new Promise((resolve, reject) => {
7
requireAuth(req, res, result => {
8
if (result instanceof Error) {
9
reject(result);
10
}
11
12
resolve(result);
13
});
14
})
15
16
res.json(`Hi from Gatsby Functions`)
17
}

Was this helpful?

Clerk © 2023