Developer Hub

Express Integration

Protect any Express route with one-line middleware.

Install

bash
npm install @certilayer/node

Setup

server.ts
import express from 'express'
import { CertiLayerClient } from '@certilayer/node'

const app = express()
const certilayer = new CertiLayerClient({
  apiKey: process.env.CERTILAYER_SECRET_KEY!
})

// Protect a single route
app.post('/checkout',
  certilayer.middleware.express(),
  (req, res) => res.json({ success: true })
)

// Custom options
app.post('/login',
  certilayer.middleware.express({ minScore: 0.90, rejectStatus: 403 }),
  loginHandler
)

// Manual verification
app.post('/transfer', async (req, res) => {
  const sessionId = req.headers['x-certilayer-session'] as string
  const { verdict, score } = await certilayer.verifySession(sessionId)

  if (verdict === 'synthetic') {
    return res.status(403).json({ error: 'bot_detected', score })
  }
  processTransfer(req, res)
})