Docs

You are viewing an archived version of the docs.Go to latest version

Handling requests with Gatsby

Gatsby Functions

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

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

src/api/clerk.js
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`)
}

For more information on how to use Express middlewares in Gatsby, refer to the Gatsby official documentation.

Feedback

What did you think of this content?

Last updated on