How it works
Everything that touches your Didit API key runs on the server, in Supabase Edge Functions (the backend of a Lovable Cloud or Supabase-connected project). The browser never sees the key.- A signed-in user clicks Verify my identity. The frontend calls the
didit-create-sessionfunction. - The function calls
POST /v3/session/with your workflow ID, the user’s ID asvendor_dataand acallbackURL, and returns the session’surl. If the user’s last session is still unfinished, it returns that session’s link instead. - The frontend sends the user to that
url. Didit’s hosted page runs the checks of your workflow, then redirects the user to thecallbackURL. - Didit sends a
status.updatedwebhook to thedidit-webhookfunction. The function verifies the signature, reads the session’s current decision from Didit and saves its status (Approved,Declined,In Reviewand so on) and theenvironment(liveorsandbox) in youruser_verificationstable, and only then answers200. - Your app reads the status from its own database. It never trusts the status in the redirect URL.
Before you start
1
Create a Didit account and a workflow
Sign up at business.didit.me. Under Workflows, create a workflow from a template and copy its workflow ID. The workflow decides what the user goes through (see Choose what to verify).
2
Copy an API key
Under Developers, then API keys, copy an API key for the application. See API keys to give it only the access it needs.
3
Have users and a backend in your Lovable project
Your project needs sign-in (so each user has an ID) and a backend that runs Edge Functions. Lovable Cloud gives you both; a connected Supabase project works the same way.
Choose what to verify
You pick the checks by picking the workflow. The code on this page does not change; only the workflow ID does.
See Workflows for every template and feature, and Pricing for what each check costs.
Part 1: Add Didit to your Lovable app
Step 1: Store your secrets
Add these as secrets of your project (in Lovable, ask it to add a secret, or add it in your backend’s secrets settings). Never put them in frontend code or in aVITE_ variable: anything in the frontend is public.
Paste this into Lovable:
Step 2: Create the verification session
Paste this into Lovable:supabase/functions/didit-create-session/index.ts
While the user’s tracked session is unfinished (
Not Started, In Progress, In Review, Resubmitted), the function returns that session’s link and creates no new one, so a user waiting on your team’s review stays on the session being reviewed. It reads the status from Didit, because the webhook may not have arrived yet. It creates a new session only after Declined, Abandoned, Expired, Kyc Expired or a sandbox approval, and answers 409 after a live approval. For a User Verification (KYC) workflow, Didit also returns the existing unfinished session when two calls race, so a double click does not create two sessions; a Business Verification workflow creates a new session on every call. If your application restricts allowed domains, the callback must be on one of them. See Create session.url in Didit’s JavaScript SDK modal instead of redirecting.
Step 3: Receive the result
Paste this into Lovable:X-Signature, the HMAC of the exact bytes Didit sent. X-Signature-V2 exists for frameworks that re-encode the body before your code sees it; an Edge Function reads the untouched bytes with req.arrayBuffer(), so it needs no canonical JSON, which would have to reproduce Didit’s own number formatting byte for byte.
supabase/functions/didit-webhook/index.ts
supabase/config.toml
- Late or repeated deliveries. Didit does not guarantee delivery order and retries a failed delivery. The function treats each delivery as a signal and saves the session’s current decision from
GET /v3/session/{session_id}/decision/, as the Webhooks page recommends, so a late delivery does not bring back the status it carried. - Other sessions. The update matches the user’s tracked
session_id, so a result of an earlier session never replaces the one the user started last. Starting a new session resets the row toNot Started. - Replays.
X-Timestampis not signed itself, so the function also requires the signed body’stimestampto equal it before it applies the 5-minute window. - Lost decisions. The function answers
200only after the decision is saved. A failed save answers500, and Didit retries twice over about five minutes; after that, resend the delivery from the destination’s Deliveries tab.
Step 4: Register the webhook in Didit
- In the Business Console, go to Developers, then Webhooks, and add a destination.
- Set its URL to your function:
https://<your-project-ref>.supabase.co/functions/v1/didit-webhook. - Subscribe it to
status.updated. - Copy its signing secret into the
DIDIT_WEBHOOK_SECRETsecret. - Send a test webhook from the destination. The function answers
200, and because test deliveries carryX-Didit-Test-Webhook: trueit writes nothing.
POST /v3/webhook/destinations/, or ask Lovable’s agent to do it through the Didit MCP server (Part 2).
Step 5: Test end to end
- Use a sandbox application while you build, so no real checks are charged. Its API key, workflow ID and webhook destination secret are the values of your secrets for now.
- Sign in to your app, click Verify my identity and finish the hosted flow.
- Back on
/verification-complete, the page showsApproved,DeclinedorIn Reviewas soon as the webhook has arrived, labelled as a test result because itsenvironmentissandbox. A session inIn Reviewchanges again when your team decides it in the console, and the webhook updates the row again; until then, the user sees that their verification is being reviewed. - Gate the features that need a verified user on
status = 'Approved'andenvironment = 'live', read on the server or through a row-level security policy, not only in the frontend. A sandbox approval never unlocks them.
Step 6: Go live
Sandbox and live are separate applications, each with its own API key, workflows and webhook destinations, so switch all three together:- In your live application, publish the workflow you tested and copy its workflow ID.
- Copy an API key of the live application.
-
Add a webhook destination in the live application with the same
didit-webhookURL, subscribed tostatus.updated, and copy its signing secret. -
Replace
DIDIT_API_KEY,DIDIT_WORKFLOW_IDandDIDIT_WEBHOOK_SECRETwith these three values at the same time, and redeploy both functions. A live key cannot open a session on a sandbox workflow, and a sandbox destination never receives live decisions. -
Clear the sandbox results, so a test session left
In Reviewdoes not keep its user from starting a live one:Each user then verifies once more in a live session: a sandbox approval does not count, and the new session starts atNot Started.
Part 2: Use Didit in the Lovable chat
Lovable’s agent can use custom MCP servers; see Lovable’s Custom MCP servers page for who can add one. Add the hosted Didit MCP server and Lovable’s agent can read and change your Didit account while you build: create the workflow, register the webhook destination, start a test session.An MCP connection gives context to Lovable’s chat only. It is never part of your published app, which talks to Didit through the functions in Part 1.
- In Lovable, open Connectors, select Add custom, and choose MCP server. If MCP server is grayed out, a workspace admin has turned off the Custom MCP setting.
- Server name:
Didit. - Server URL:
https://mcp.didit.me/mcp. - Keep OAuth as the authentication option and click Add & authorize.
- Complete Log in with Didit in the window that opens and approve the organizations Lovable may use.
No API key needed. With OAuth the server acts as you, in the organizations you approve at sign-in, with your role’s permissions. To connect with an application API key instead, choose Bearer token or API key, paste the key and click Add server: the server accepts it as a bearer token. See Authentication.
Check that it works
In a Lovable chat, ask:- “Create a sandbox KYC workflow with ID verification, liveness and face match, and give me its workflow ID.”
- “Register a Didit webhook destination for status.updated pointing at my didit-webhook Edge Function, and tell me where to find its signing secret.”
- “Create a test session for my user ID and give me the verification link.”
Troubleshooting
- Sign-in fails or loops. Log in at business.didit.me in the same browser first, then click Add & authorize again.
- A tool answers with
missing_scope. Your role in that organization lacks the permission. See roles and permissions. - The webhook function returns
401. Check thatDIDIT_WEBHOOK_SECRETis the secret of the destination that sends the webhook, that the function is deployed withverify_jwt = false, and that it reads the body withreq.arrayBuffer()before anything parses or re-encodes it. A401on the timestamp check means the delivery is more than five minutes old, or the server clock is off. didit-create-sessionreturns409. Didit reports the user’s tracked session as approved in live. The page re-reads the row, which the webhook updates.didit-create-sessionreturns502. Didit could not be reached, or an unfinished session has no link to resume. Nothing new is created; try again.- The session request returns
400oncallback. Add your app’s address to the application’s allowed domains, or checkAPP_URL.
Next steps
Webhooks
Every event, payload field and signature header.
Create session
All request fields, such as expected details and metadata.
MCP tools reference
Everything Lovable’s agent can call, tool by tool.
Pricing
What each check in your workflow costs.