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.
1import { ClerkExpressRequireAuth } from '@clerk/clerk-sdk-node';23const requireAuth = ClerkExpressRequireAuth();45export default async function clerkHandler(req, res) {6await new Promise((resolve, reject) => {7requireAuth(req, res, result => {8if (result instanceof Error) {9reject(result);10}1112resolve(result);13});14})1516res.json(`Hi from Gatsby Functions`)17}
For more information on how to use Express middlewares in Gatsby refer to the Gatsby official documentation.