Skip to main content

Replit integration

@blursec/replit is the official Replit adapter for @blursec/sdk — zero-config credential & session leak protection for apps hosted on Replit. The core SDK is already isomorphic and runs on Replit without any adapter. This package layers on the Replit-specific wiring that is tedious to do by hand: Like everything else in the Blursec ecosystem it fails open on outages, adds ~50 ms to a login, and runs on every Replit-supported runtime (Node 18+, Bun, Deno).

Install

@blursec/sdk is a peer dependency, so the adapter and the SDK version independently — bring any SDK >= 1.0.0.

Quick start (Replit + Express)

  1. Open your Repl’s Secrets pane (lock icon in the left sidebar).
  2. Add a secret named BLURSEC_API_KEY with your Blursec API key.
  3. Drop this into index.ts:
Both middlewares fail open on Blursec outages — your login flow keeps working even if the API is unreachable.

createBlursecFromReplit(overrides?)

Env-aware constructor. Every field of BlursecClientConfig may be overridden via the overrides argument. Throws BlursecValidationError when BLURSEC_API_KEY is missing.

blursecSession(blursec, options?)

Express middleware. Verifies the inbound session token against the stealer-log feed. Decision matrix: When the SDK fails open (timeout, network, 5xx, circuit open) the middleware passes through unchanged.

blursecLogin(blursec, options?)

Express middleware for POST /login. Runs body[emailField] + body[passwordField] through blursec.checkCredential before returning control to your password-verification handler. The decision matrix matches blursecSession, except block responds 403 JSON by default.

Replit Auth identity

blursecReplitIdentity() attaches a typed identity parsed from the X-Replit-User-* headers to req.blursec.identity. It never short-circuits the response — pair it with your own logic for routes that require Replit Auth. replitAuthHeaders(req) is the framework-agnostic version: it accepts any RequestLike (WHATWG Request, Node IncomingMessage, Express req, or bare { headers }) and returns an unauthenticated identity (isAuthenticated: false) when no headers are present.

TypeScript: augmenting Request.blursec

The Express adapters attach state to req.blursec. For type completion in your handlers, add this to a *.d.ts in your project:
Pass dryRun: true for the first 1–2 weeks so you can dashboard the real signal without enforcing:
recommendedAction will always be "allow"; the would-be action is surfaced via result.enforcedAction. Flip dryRun off when your dashboards are clean. See the runnable example in examples/replit-express.ts and the error model in errors.