> ## Documentation Index
> Fetch the complete documentation index at: https://docs.didit.me/llms.txt
> Use this file to discover all available pages before exploring further.

# Lovable ऐप में Didit से KYC जोड़ें

> Lovable ऐप में दो Supabase Edge Functions और कॉपी-पेस्ट प्रॉम्प्ट्स से Didit KYC, आयु सत्यापन या AML स्क्रीनिंग जोड़ें।

Didit दो सर्वर-साइड फ़ंक्शन के ज़रिए Lovable में बनी ऐप में पहचान सत्यापन (KYC), आयु सत्यापन और AML स्क्रीनिंग जोड़ता है: एक फ़ंक्शन Didit का सत्यापन सत्र बनाता है और उसका लिंक लौटाता है, और दूसरा फ़ंक्शन Didit का हस्ताक्षरित webhook प्राप्त करता है और उस उपयोगकर्ता का परिणाम आपके डेटाबेस में सहेजता है।
आप Didit MCP सर्वर को Lovable की चैट से भी जोड़ सकते हैं, ताकि Lovable का एजेंट ऐप बनाते समय आपके Didit खाते में वर्कफ़्लो, परीक्षण सत्र और webhook गंतव्य बना सके।

यह पेज हर चरण के लिए एक प्रॉम्प्ट देता है जिसे आप Lovable में पेस्ट कर सकते हैं, और वह कोड जो वह प्रॉम्प्ट बनाना चाहिए, ताकि आप जाँच सकें कि Lovable ने क्या लिखा है।

***

## कैसे काम करता है

आपकी Didit API कुंजी से जुड़ी हर चीज़ सर्वर पर चलती है, Supabase Edge Functions में (Lovable Cloud या Supabase से जुड़े प्रोजेक्ट के बैकएंड में)।
ब्राउज़र कुंजी कभी नहीं देखता।

1. साइन इन किया हुआ उपयोगकर्ता **मेरी पहचान सत्यापित करें** पर क्लिक करता है। फ़्रंटएंड `didit-create-session` फ़ंक्शन को कॉल करता है।
2. यह फ़ंक्शन [`POST /v3/session/`](https://docs.didit.me/hi/sessions-api/create-session) को कॉल करता है, जिसमें आपकी वर्कफ़्लो ID, `vendor_data` के रूप में उपयोगकर्ता की ID और एक `callback` URL भेजा जाता है, और सत्र का `url` लौटाता है। यदि उपयोगकर्ता का पिछला सत्र अभी पूरा नहीं हुआ है, तो यह उस सत्र का लिंक लौटाता है।
3. फ़्रंटएंड उपयोगकर्ता को उस `url` पर भेजता है। Didit का होस्टेड पेज आपकी वर्कफ़्लो की जाँच चलाता है, फिर उपयोगकर्ता को `callback` URL पर रीडायरेक्ट करता है।
4. Didit `didit-webhook` फ़ंक्शन को एक `status.updated` [webhook](https://docs.didit.me/hi/integration/webhooks.md) भेजता है। फ़ंक्शन हस्ताक्षर सत्यापित करता है, Didit से सत्र का मौजूदा निर्णय पढ़ता है, और स्थिति (`Approved`, `Declined`, `In Review` आदि) और `environment` (`live` या `sandbox`) को आपकी `user_verifications` टेबल में सहेजता है। इसके बाद ही यह `200` का जवाब देता है।
5. आपका ऐप स्थिति अपने डेटाबेस से पढ़ता है। वह रीडायरेक्ट URL में दी गई स्थिति पर कभी भरोसा नहीं करता।

***

## शुरू करने से पहले

**1. Didit खाता और वर्कफ़्लो बनाएँ**

[business.didit.me](https://business.didit.me) पर साइन अप करें। **Workflows** के अंतर्गत टेम्पलेट से एक वर्कफ़्लो बनाएँ और उसकी **workflow ID** कॉपी करें। वर्कफ़्लो तय करता है कि उपयोगकर्ता किन चरणों से गुज़रेगा (देखें [जाँच चुनें](#सत्यापन-के-लिए-जाँच-चुनें))।

**2. API कुंजी कॉपी करें**

**Developers** और फिर **API keys** के अंतर्गत एप्लिकेशन के लिए एक API कुंजी कॉपी करें। केवल आवश्यक पहुँच देने के लिए [API keys](https://docs.didit.me/hi/console/api-keys.md) देखें।

**3. अपने Lovable प्रोजेक्ट में उपयोगकर्ता और बैकएंड रखें**

आपके प्रोजेक्ट में साइन-इन होना चाहिए (ताकि हर उपयोगकर्ता की एक ID हो) और एक बैकएंड जो Edge Functions चलाता हो। Lovable Cloud ये दोनों देता है; कनेक्टेड Supabase प्रोजेक्ट भी इसी तरह काम करता है।

### सत्यापन के लिए जाँच चुनें

आप वर्कफ़्लो चुनकर जाँच तय करते हैं। इस पेज का कोड नहीं बदलता; केवल workflow ID बदलती है।

| आपको क्या चाहिए | वर्कफ़्लो | उपयोगकर्ता क्या करता है |
| - | - | - |
| पूर्ण KYC | **KYC** टेम्पलेट, जिसमें [पहचान सत्यापन](https://docs.didit.me/hi/core-technology/id-verification/overview.md), [लाइवनेस डिटेक्शन](https://docs.didit.me/hi/core-technology/liveness/overview.md) और [चेहरा मिलान](https://docs.didit.me/hi/core-technology/face-match/overview.md) शामिल हैं | पहचान दस्तावेज़ स्कैन करता है और लाइव सेल्फ़ी लेता है, जिसका दस्तावेज़ की फ़ोटो से मिलान होता है |
| आयु सत्यापन | **Adaptive Age Verification** टेम्पलेट ([आयु अनुमान](https://docs.didit.me/hi/core-technology/age-estimation/overview.md)) | सेल्फ़ी लेता है; केवल आपकी आयु सीमा के आसपास के उपयोगकर्ताओं से पहचान दस्तावेज़ माँगा जाता है |
| AML के साथ KYC | **KYC** टेम्पलेट, जिसमें [AML स्क्रीनिंग](https://docs.didit.me/hi/core-technology/aml-screening/overview.md) जोड़ी गई है | पूर्ण KYC के समान; Didit व्यक्ति की भी प्रतिबंध, PEP और प्रतिकूल मीडिया सूचियों के विरुद्ध जाँच करता है |

हर टेम्पलेट और सुविधा के लिए [Workflows](https://docs.didit.me/hi/console/workflows.md) देखें, और हर जाँच की लागत के लिए [मूल्य निर्धारण](https://docs.didit.me/hi/getting-started/pricing.md) देखें।

***

## भाग 1: अपने Lovable ऐप में Didit जोड़ें

### चरण 1: अपने सीक्रेट सहेजें

इन्हें अपने प्रोजेक्ट के सीक्रेट के रूप में जोड़ें (Lovable में, उससे सीक्रेट जोड़ने को कहें, या अपने बैकएंड की सीक्रेट सेटिंग्स में जोड़ें)। इन्हें कभी भी फ़्रंटएंड कोड में या `VITE_` वेरिएबल में न रखें: फ़्रंटएंड में मौजूद कोई भी चीज़ सार्वजनिक होती है।

| सीक्रेट | मान |
| - | - |
| `DIDIT_API_KEY` | **Developers > API keys** से मिली API कुंजी। दोनों फ़ंक्शन इसका उपयोग करते हैं |
| `DIDIT_WORKFLOW_ID` | **Workflows** से मिली वर्कफ़्लो ID |
| `DIDIT_WEBHOOK_SECRET` | आपके webhook गंतव्य का हस्ताक्षर सीक्रेट (इसे [चरण 4](#चरण-4-didit-में-webhook-रजिस्टर-करें) में बनाया जाता है) |
| `APP_URL` | आपके ऐप का सार्वजनिक पता, उदाहरण के लिए `https://your-app.lovable.app` |

यह Lovable में पेस्ट करें:

```text theme={null}
Add four backend secrets to this project: DIDIT_API_KEY, DIDIT_WORKFLOW_ID, DIDIT_WEBHOOK_SECRET and APP_URL. Ask me for their values. They must only ever be read inside Edge Functions with Deno.env.get, never in frontend code.
```

### चरण 2: सत्यापन सत्र बनाएँ

यह Lovable में पेस्ट करें:

````text theme={null}
Add identity verification with Didit.

1. Database: run this SQL migration exactly as written.

```sql
-- One row per user who started a verification. Users read their own row; only the two functions below write it.
create table public.user_verifications (
  user_id uuid primary key references auth.users (id) on delete cascade,
  session_id text not null,        -- the Didit session this user started last
  status text not null default 'Not Started',
  environment text,                -- 'live' or 'sandbox', as Didit reports it
  updated_at timestamptz not null default now()
);
alter table public.user_verifications enable row level security;
create policy "Users read their own verification" on public.user_verifications
  for select to authenticated using ((select auth.uid()) = user_id);
-- Data API access: the signed-in user reads their row, the Edge Functions write it with the service role.
grant select on public.user_verifications to authenticated;
grant select, insert, update on public.user_verifications to service_role;
```

2. Create a Supabase Edge Function named didit-create-session that:
   - handles CORS (including OPTIONS) so the frontend can call it with supabase.functions.invoke;
   - reads the signed-in user from the Authorization header with supabase.auth.getUser(); returns 401 if there is none;
   - reads the user's row with the service role key (returns 500 if that read fails);
   - when the row has a session_id, reads GET https://verification.didit.me/v3/session/{session_id}/decision/ with
     the header x-api-key: DIDIT_API_KEY, and decides from Didit's answer, not from the row:
     - status 'Approved' with environment 'live': returns 409 with { status, environment };
     - status 'Declined', 'Abandoned', 'Expired' or 'Kyc Expired', a sandbox 'Approved', or a 404: goes on to create
       a new session;
     - any other status (Not Started, In Progress, In Review, Resubmitted and so on): returns { "url": <its
       session_url> } and never creates a new session; returns 502 if it has no session_url;
     - any other error: returns 502;
   - to create a session, calls POST https://verification.didit.me/v3/session/ with the header x-api-key: DIDIT_API_KEY
     and the JSON body { "workflow_id": DIDIT_WORKFLOW_ID, "vendor_data": <the user's id>,
     "callback": APP_URL + "/verification-complete" };
   - upserts the user's row with the new session_id, status 'Not Started' and environment null; returns 500 without
     the link if that write fails;
   - returns { "url": <the url field of Didit's response> }. The field is called url, not verification_url.
   Never accept the user id from the request body, and never send DIDIT_API_KEY to the browser.

3. Frontend: on the account page, read the user's row from user_verifications. The user is verified only when
   status = 'Approved' AND environment = 'live'. When environment is 'sandbox', show the status labelled "Test result".
   When status is 'In Review', show "Your verification is being reviewed" and no button.
   Otherwise, if the user is not verified, show a "Verify my identity" button that calls didit-create-session and
   then does window.location.href = url. On a 409 answer, re-read the user's row and show its status.
   Add a /verification-complete page that says "Thanks, we're checking your verification" and re-reads the user's
   status and environment every 3 seconds until status is 'Approved', 'Declined' or 'In Review', for up to 2 minutes;
   if it is still pending after that, show a "Refresh" button. If a read fails, stop and show "Try again" (or
   "Sign in" when the user is signed out), not the pending message. Do not trust the status query parameter Didit
   adds to that URL.
````

फ़ंक्शन कुछ ऐसा दिखना चाहिए:

```typescript supabase/functions/didit-create-session/index.ts theme={null}
import { createClient } from "npm:@supabase/supabase-js@2";

const corsHeaders = {
  "Access-Control-Allow-Origin": "*",
  "Access-Control-Allow-Headers": "authorization, x-client-info, apikey, content-type",
};

// Sessions that allow a new attempt. A sandbox approval does too; a live approval does not.
const CAN_RETRY = ["Declined", "Abandoned", "Expired", "Kyc Expired"];

function json(body: unknown, status = 200) {
  return new Response(JSON.stringify(body), {
    status,
    headers: { ...corsHeaders, "Content-Type": "application/json" },
  });
}

Deno.serve(async (req) => {
  if (req.method === "OPTIONS") return new Response("ok", { headers: corsHeaders });

  // Who is asking: the signed-in user, from their own session token.
  const supabase = createClient(
    Deno.env.get("SUPABASE_URL")!,
    Deno.env.get("SUPABASE_ANON_KEY")!,
    { global: { headers: { Authorization: req.headers.get("Authorization") ?? "" } } },
  );
  const { data: { user } } = await supabase.auth.getUser();
  if (!user) return json({ error: "Not signed in" }, 401);

  const admin = createClient(
    Deno.env.get("SUPABASE_URL")!,
    Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!,
  );
  const didit = { "x-api-key": Deno.env.get("DIDIT_API_KEY")!, "Content-Type": "application/json" };

  const { data: current, error: readError } = await admin
    .from("user_verifications")
    .select("session_id")
    .eq("user_id", user.id)
    .maybeSingle();
  if (readError) return json({ error: "Could not start verification" }, 500);

  // Ask Didit how the tracked session stands: its webhook may not have arrived yet.
  if (current) {
    const check = await fetch(
      `https://verification.didit.me/v3/session/${encodeURIComponent(current.session_id)}/decision/`,
      { headers: didit },
    );
    if (check.ok) {
      const tracked = await check.json();
      if (tracked.status === "Approved" && tracked.environment === "live") {
        return json({ error: "Already verified", status: tracked.status, environment: tracked.environment }, 409);
      }
      // Unfinished (Not Started, In Progress, In Review, Resubmitted): resume it, never start a second one.
      if (!CAN_RETRY.includes(tracked.status) && tracked.status !== "Approved") {
        return tracked.session_url
          ? json({ url: tracked.session_url })
          : json({ error: "Could not resume verification" }, 502);
      }
    } else if (check.status !== 404) {
      // 404: the session no longer exists, so a new one is fine. Anything else: do not guess.
      return json({ error: "Could not start verification" }, 502);
    }
  }

  const response = await fetch("https://verification.didit.me/v3/session/", {
    method: "POST",
    headers: didit,
    body: JSON.stringify({
      workflow_id: Deno.env.get("DIDIT_WORKFLOW_ID"),
      vendor_data: user.id,
      callback: `${Deno.env.get("APP_URL")}/verification-complete`,
    }),
  });
  const session = await response.json();
  if (!response.ok) {
    console.error("Didit session error", response.status, session);
    return json({ error: "Could not start verification" }, 502);
  }

  // Track the new session before handing out its link: the webhook saves results for this session only.
  const { error } = await admin.from("user_verifications").upsert({
    user_id: user.id,
    session_id: session.session_id,
    status: "Not Started",
    environment: null,
    updated_at: new Date().toISOString(),
  });
  if (error) return json({ error: "Could not start verification" }, 500);

  return json({ url: session.url });
});
```

बटन:

```typescript theme={null}
const { data, error } = await supabase.functions.invoke("didit-create-session");
if (data?.url) window.location.href = data.url;
else if (error?.context?.status === 409) await loadVerification(); // Re-read the user's row and show its status.
else showError();
```

पूर्णता पेज webhook का इंतज़ार करता है, क्योंकि उपयोगकर्ता webhook आने से पहले ही वहाँ पहुँच सकता है:

```typescript theme={null}
// Re-read the user's own row every 3 seconds, for up to 2 minutes.
const SETTLED = ["Approved", "Declined", "In Review"];
type Decision = { status: string; environment: string | null };
async function waitForDecision(userId: string): Promise<Decision | "pending" | "error"> {
  for (let attempt = 0; attempt < 40; attempt++) {
    const { data, error } = await supabase
      .from("user_verifications")
      .select("status, environment")
      .eq("user_id", userId)
      .maybeSingle();
    // A failed read is not a pending decision: show "Try again", or "Sign in" when the user is signed out.
    if (error) return "error";
    // environment 'sandbox' is labelled "Test result".
    if (data && SETTLED.includes(data.status)) return data;
    await new Promise((resolve) => setTimeout(resolve, 3000));
  }
  return "pending"; // Still pending: show a Refresh button.
}
```

> [!NOTE]
>
> जब उपयोगकर्ता का ट्रैक किया गया सत्र अधूरा हो (`Not Started`, `In Progress`, `In Review`, `Resubmitted`), तब फ़ंक्शन उसी सत्र का लिंक लौटाता है और कोई नया सत्र नहीं बनाता, ताकि आपकी टीम की समीक्षा का इंतज़ार कर रहा उपयोगकर्ता उसी सत्र पर बना रहे जिसकी समीक्षा हो रही है। यह Didit से स्थिति पढ़ता है, क्योंकि webhook अभी तक नहीं पहुँचा हो सकता है। यह केवल `Declined`, `Abandoned`, `Expired`, `Kyc Expired` या सैंडबॉक्स स्वीकृति के बाद नया सत्र बनाता है, और लाइव स्वीकृति के बाद `409` का जवाब देता है। उपयोगकर्ता सत्यापन (KYC) वर्कफ़्लो के लिए, Didit दो कॉल एक साथ आने पर मौजूदा अधूरा सत्र भी लौटाता है, ताकि डबल क्लिक से दो सत्र न बनें; व्यवसाय सत्यापन वर्कफ़्लो हर कॉल पर नया सत्र बनाता है। यदि आपका ऐप **allowed domains** को सीमित करता है, तो `callback` उनमें से किसी एक पर होना चाहिए। देखें [सत्र बनाएँ](https://docs.didit.me/hi/sessions-api/create-session.md)।

क्या आप उपयोगकर्ता को अपने ऐप के भीतर रखना चाहते हैं? रीडायरेक्ट करने के बजाय उसी `url` को Didit के [JavaScript SDK](https://docs.didit.me/hi/integration/web-sdks/javascript-sdk.md) मोडल में खोलें।

### चरण 3: परिणाम प्राप्त करें

यह Lovable में पेस्ट करें:

```text theme={null}
Create a Supabase Edge Function named didit-webhook that receives Didit webhooks. It is called by Didit, not by a
signed-in user, so deploy it without JWT verification (verify_jwt = false for this function in supabase/config.toml).

For each POST request:
1. Read the body as raw bytes with req.arrayBuffer(). Do not call req.json() and do not re-serialize the body
   before the signature check. Parse it with JSON.parse only to read its fields.
2. Signature: compute HMAC-SHA256 with DIDIT_WEBHOOK_SECRET, hex encoded, over the raw bytes, and compare it in
   constant time (timingSafeEqual from node:crypto, on TextEncoder bytes; Deno has no global Buffer) with the
   X-Signature header and, when present, X-Signature-Previous. Return 401 if neither matches. Parse the body only
   after this check.
3. Timestamp: return 401 unless X-Timestamp is an integer, the body's timestamp field equals it, and
   abs(now_in_seconds - X-Timestamp) <= 300.
4. Return 200 without writing anything when the header X-Didit-Test-Webhook is "true" or webhook_type is not
   "status.updated", or when vendor_data is not a user id (a UUID).
5. Do not save the status from the body: deliveries can arrive late or out of order. Read the session's current
   decision with GET https://verification.didit.me/v3/session/{session_id}/decision/ and the header
   x-api-key: DIDIT_API_KEY. Return 200 on a 404 (the session no longer exists) and 500 on any other error.
6. With the service role key, update user_verifications set status and environment from that decision, and
   updated_at = now(), where user_id = vendor_data from the body and session_id = session_id from the body.
   No ordering logic: the decision Didit returns is the current one.
7. Return 200 only after the update succeeds. If it fails, return 500 so Didit retries the delivery.
```

फ़ंक्शन कुछ ऐसा दिखना चाहिए। यह Webhooks पेज के [हस्ताक्षर सत्यापन](https://docs.didit.me/hi/integration/webhooks.md#हस्ताक्षर-सत्यापन) का पालन करता है, `X-Signature` के साथ, जो Didit द्वारा भेजे गए बिल्कुल उन्हीं बाइट्स का HMAC है। `X-Signature-V2` उन फ़्रेमवर्क के लिए है जो आपके कोड तक पहुँचने से पहले body को फिर से एन्कोड कर देते हैं; एक Edge Function `req.arrayBuffer()` से बिना बदले बाइट्स पढ़ता है, इसलिए उसे कैनॉनिकल JSON की ज़रूरत नहीं होती, जिसे Didit की अपनी संख्या-फ़ॉर्मेटिंग को बाइट-दर-बाइट दोहराना पड़ता।

```typescript supabase/functions/didit-webhook/index.ts theme={null}
import { createHmac, timingSafeEqual } from "node:crypto";
import { createClient } from "npm:@supabase/supabase-js@2";

const SECRET = Deno.env.get("DIDIT_WEBHOOK_SECRET")!;
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
const encoder = new TextEncoder();

// Constant-time comparison of two hex digests, as bytes.
function sameDigest(expected: string, received: string | null): boolean {
  if (!received) return false;
  const a = encoder.encode(expected);
  const b = encoder.encode(received);
  return a.length === b.length && timingSafeEqual(a, b);
}

const ok = () => Response.json({ ok: true });
const reject = (message: string) => new Response(message, { status: 401 });
const retry = (message: string) => new Response(message, { status: 500 });

Deno.serve(async (req) => {
  if (req.method !== "POST") return new Response("Method not allowed", { status: 405 });

  // 1. The exact bytes Didit sent.
  const raw = new Uint8Array(await req.arrayBuffer());

  // 2. Signature over those bytes. X-Signature-Previous is sent for 24 hours after you rotate the signing secret.
  const digest = createHmac("sha256", SECRET).update(raw).digest("hex");
  if (
    !sameDigest(digest, req.headers.get("X-Signature")) &&
    !sameDigest(digest, req.headers.get("X-Signature-Previous"))
  ) {
    return reject("Invalid signature");
  }
  const body = JSON.parse(new TextDecoder().decode(raw));

  // 3. Freshness, from the signed body: its timestamp must match X-Timestamp and be under 5 minutes old.
  const timestamp = Number(req.headers.get("X-Timestamp"));
  if (
    !Number.isInteger(timestamp) ||
    body.timestamp !== timestamp ||
    Math.abs(Date.now() / 1000 - timestamp) > 300
  ) {
    return reject("Stale or mismatched timestamp");
  }

  // 4. Test deliveries carry sample data, and this app stores session results only.
  if (req.headers.get("X-Didit-Test-Webhook") === "true") return ok();
  if (body.webhook_type !== "status.updated") return ok();
  if (!UUID.test(String(body.vendor_data ?? ""))) {
    console.warn("status.updated without an app user id", body.session_id);
    return ok();
  }

  // 5. Didit is the source of truth: read the session's current decision, not the event's status.
  const check = await fetch(
    `https://verification.didit.me/v3/session/${encodeURIComponent(body.session_id)}/decision/`,
    { headers: { "x-api-key": Deno.env.get("DIDIT_API_KEY")! } },
  );
  if (check.status === 404) return ok();
  if (!check.ok) return retry("Could not read the decision");
  const decision = await check.json();

  // 6. Save it on the user's row, only for the session the user started last.
  const admin = createClient(
    Deno.env.get("SUPABASE_URL")!,
    Deno.env.get("SUPABASE_SERVICE_ROLE_KEY")!,
  );
  const { error } = await admin
    .from("user_verifications")
    .update({ status: decision.status, environment: decision.environment, updated_at: new Date().toISOString() })
    .eq("user_id", body.vendor_data)
    .eq("session_id", body.session_id);

  // 7. Acknowledge only what is saved: a 500 makes Didit retry the delivery.
  if (error) {
    console.error("Could not save the Didit decision", body.event_id, error);
    return retry("Could not save");
  }
  return ok();
});
```

```toml supabase/config.toml theme={null}
[functions.didit-webhook]
verify_jwt = false
```

> [!WARNING]
>
> JWT सत्यापन बंद करना केवल इस फ़ंक्शन के लिए सही है: Didit Supabase token नहीं भेज सकता, इसलिए HMAC हस्ताक्षर ही यह साबित करता है कि अनुरोध Didit से आया है। `didit-create-session` के लिए JWT सत्यापन चालू रखें।

कोड किन चीज़ों से बचाता है:

* **देर से या दोहराई गई डिलीवरी।** Didit [डिलीवरी के क्रम](https://docs.didit.me/hi/integration/webhooks.md#डिलीवरी-का-क्रम) की गारंटी नहीं देता और विफल डिलीवरी को दोबारा भेजता है। फ़ंक्शन हर डिलीवरी को एक संकेत मानता है और Webhooks पेज की सिफ़ारिश के अनुसार [`GET /v3/session/{session_id}/decision/`](https://docs.didit.me/hi/sessions-api/retrieve-session) से सत्र का मौजूदा निर्णय सहेजता है, ताकि देर से आई डिलीवरी वह स्थिति वापस न लाए जो वह लेकर आई थी।
* **अन्य सत्र।** अपडेट उपयोगकर्ता के ट्रैक किए गए `session_id` से मेल खाता है, इसलिए किसी पिछले सत्र का परिणाम कभी उस सत्र की जगह नहीं लेता जिसे उपयोगकर्ता ने आखिरी बार शुरू किया था। नया सत्र शुरू करने पर पंक्ति `Not Started` पर रीसेट हो जाती है।
* **रीप्ले।** `X-Timestamp` स्वयं हस्ताक्षरित नहीं होता, इसलिए फ़ंक्शन 5 मिनट की विंडो लागू करने से पहले यह भी माँगता है कि हस्ताक्षरित body का `timestamp` उसके बराबर हो।
* **खोए हुए निर्णय।** फ़ंक्शन `200` का जवाब तभी देता है जब निर्णय सहेज लिया गया हो। विफल सहेजने पर `500` का जवाब मिलता है, और Didit लगभग पाँच मिनट में दो बार [पुनः प्रयास](https://docs.didit.me/hi/integration/webhooks.md#पुनः-प्रयास-नीति) करता है; उसके बाद गंतव्य के **Deliveries** टैब से डिलीवरी फिर से भेजें।

पूरे payload, हर स्थिति मान और अन्य इवेंट के लिए [Webhooks](https://docs.didit.me/hi/integration/webhooks.md) देखें।

### चरण 4: Didit में webhook रजिस्टर करें

1. Business Console में, **Developers** पर जाएँ, फिर **Webhooks** पर, और एक गंतव्य जोड़ें।
2. इसका URL अपने फ़ंक्शन पर सेट करें: `https://<your-project-ref>.supabase.co/functions/v1/didit-webhook`।
3. इसे `status.updated` की सदस्यता दें।
4. इसका हस्ताक्षर सीक्रेट `DIDIT_WEBHOOK_SECRET` सीक्रेट में कॉपी करें।
5. गंतव्य से एक टेस्ट webhook भेजें। फ़ंक्शन `200` का जवाब देता है, और चूँकि टेस्ट डिलीवरी में `X-Didit-Test-Webhook: true` होता है, यह कुछ भी नहीं लिखता।

आप [`POST /v3/webhook/destinations/`](https://docs.didit.me/hi/integration/webhooks) से भी गंतव्य बना सकते हैं, या Didit MCP सर्वर के ज़रिए यह काम करने के लिए Lovable के एजेंट से कह सकते हैं ([भाग 2](#भाग-2-lovable-चैट-में-didit-का-उपयोग-करें))।

### चरण 5: अंत से अंत तक जाँचें

1. निर्माण के दौरान [सैंडबॉक्स एप्लिकेशन](https://docs.didit.me/hi/integration/sandbox-testing.md) का उपयोग करें, ताकि कोई वास्तविक जाँच शुल्क न लगे। इसकी API कुंजी, वर्कफ़्लो ID और webhook गंतव्य सीक्रेट अभी के लिए आपके सीक्रेट के मान हैं।
2. अपने ऐप में साइन इन करें, **Verify my identity** पर क्लिक करें और होस्टेड फ़्लो पूरा करें।
3. `/verification-complete` पर वापस आने पर, webhook पहुँचते ही पेज `Approved`, `Declined` या `In Review` दिखाता है, और इसे परीक्षण परिणाम के रूप में लेबल किया जाता है क्योंकि इसका `environment` `sandbox` है। `In Review` वाला सत्र तब बदलता है जब आपकी टीम कंसोल में उसका निर्णय लेती है, और webhook पंक्ति को फिर से अपडेट करता है; तब तक उपयोगकर्ता देखता है कि उसके सत्यापन की समीक्षा हो रही है।
4. जिन सुविधाओं के लिए सत्यापित उपयोगकर्ता चाहिए, उन्हें `status = 'Approved'` **और** `environment = 'live'` पर सीमित करें, इसे सर्वर पर या पंक्ति-स्तरीय सुरक्षा नीति के ज़रिए पढ़ें, केवल फ़्रंटएंड में नहीं। सैंडबॉक्स स्वीकृति इन्हें कभी अनलॉक नहीं करती।

### चरण 6: लाइव जाएँ

सैंडबॉक्स और लाइव अलग-अलग एप्लिकेशन हैं, जिनकी अपनी API कुंजी, वर्कफ़्लो और webhook गंतव्य होते हैं, इसलिए तीनों को एक साथ बदलें:

1. अपने लाइव एप्लिकेशन में, वह वर्कफ़्लो प्रकाशित करें जिसका आपने परीक्षण किया था, और उसका वर्कफ़्लो ID कॉपी करें।
2. लाइव एप्लिकेशन की एक API कुंजी कॉपी करें।
3. लाइव एप्लिकेशन में उसी `didit-webhook` URL के साथ एक webhook गंतव्य जोड़ें, जिसे `status.updated` की सदस्यता हो, और उसका हस्ताक्षर सीक्रेट कॉपी करें।
4. `DIDIT_API_KEY`, `DIDIT_WORKFLOW_ID` और `DIDIT_WEBHOOK_SECRET` को इन तीन मानों से एक साथ बदलें, और दोनों फ़ंक्शन फिर से डिप्लॉय करें। लाइव कुंजी सैंडबॉक्स वर्कफ़्लो पर सत्र नहीं खोल सकती, और सैंडबॉक्स गंतव्य को लाइव निर्णय कभी नहीं मिलते।
5. सैंडबॉक्स के परिणाम साफ़ करें, ताकि `In Review` पर छूटा परीक्षण सत्र उपयोगकर्ता को लाइव सत्र शुरू करने से न रोके:

   ```sql theme={null}
   delete from public.user_verifications where environment = 'sandbox';
   ```

इसके बाद हर उपयोगकर्ता एक लाइव सत्र में एक बार फिर सत्यापन करता है: सैंडबॉक्स की स्वीकृति नहीं गिनी जाती, और नया सत्र `Not Started` स्थिति से शुरू होता है।

***

## भाग 2: Lovable चैट में Didit का उपयोग करें

Lovable का एजेंट कस्टम MCP सर्वर का उपयोग कर सकता है। किसे इसे जोड़ने की अनुमति है, यह जानने के लिए Lovable का [Custom MCP servers](https://docs.lovable.dev/integrations/custom-mcp) पेज देखें। होस्टेड Didit MCP सर्वर जोड़ने पर Lovable का एजेंट आपके बनाते समय आपके Didit खाते को पढ़ और बदल सकता है: वर्कफ़्लो बनाना, webhook गंतव्य पंजीकृत करना और टेस्ट सत्र शुरू करना।

> [!NOTE]
>
> MCP कनेक्शन केवल Lovable की **चैट** को संदर्भ उपलब्ध कराता है। यह कभी भी आपके प्रकाशित ऐप का हिस्सा नहीं होता, जो [भाग 1](#भाग-1-अपने-lovable-ऐप-में-didit-जोड़ें) के फ़ंक्शनों के माध्यम से Didit से बात करता है।

1. Lovable में **Connectors** खोलें, **Add custom** चुनें, और **MCP server** चुनें। यदि **MCP server** धूसर दिखे, तो किसी वर्कस्पेस एडमिन ने **Custom MCP** सेटिंग बंद कर दी है।
2. **Server name:** `Didit`
3. **Server URL:** `https://mcp.didit.me/mcp`
4. प्रमाणीकरण विकल्प के रूप में **OAuth** रहने दें और **Add & authorize** पर क्लिक करें।
5. खुलने वाली विंडो में **Log in with Didit** की प्रक्रिया पूरी करें और उन संगठनों को स्वीकृत करें जिनका उपयोग Lovable कर सकता है।

इसके बाद सर्वर आपके चैट कनेक्टर में दिखने लगता है। यह कनेक्शन व्यक्तिगत है: जो भी टीम सदस्य इसका उपयोग करना चाहता है, वह इसे स्वयं कनेक्ट करता है।

> [!NOTE]
>
> **API कुंजी की ज़रूरत नहीं।** OAuth के साथ सर्वर आपकी ओर से काम करता है, उन संगठनों में जिन्हें आप साइन-इन के समय स्वीकृत करते हैं, और आपकी भूमिका की अनुमतियों के साथ। यदि आप इसके बजाय एप्लिकेशन API कुंजी से कनेक्ट करना चाहते हैं, तो **Bearer token or API key** चुनें, कुंजी चिपकाएँ और **Add server** पर क्लिक करें: सर्वर इसे बेयरर टोकन के रूप में स्वीकार करता है। देखें [Authentication](https://docs.didit.me/hi/integration/mcp/authentication.md)।

### जाँचें कि यह काम करता है

Lovable चैट में पूछें:

```text theme={null}
Use the Didit MCP server to call didit_context_get and list my organizations and applications.
```

इसके बाद इसका उपयोग करें:

* "पहचान सत्यापन, लाइवनेस डिटेक्शन और चेहरा मिलान के साथ एक सैंडबॉक्स KYC वर्कफ़्लो बनाओ, और मुझे उसका वर्कफ़्लो ID दो।"
* "status.updated के लिए एक Didit webhook गंतव्य पंजीकृत करो, जो मेरे didit-webhook Edge Function की ओर इशारा करे, और बताओ कि उसका साइनिंग सीक्रेट कहाँ मिलेगा।"
* "मेरे उपयोगकर्ता ID के लिए एक टेस्ट सत्र बनाओ और मुझे सत्यापन लिंक दो।"

Lovable केवल-पढ़ने वाले टूल बिना पूछे चलाता है, और किसी भी ऐसे टूल से पहले आपकी स्वीकृति माँगता है जो कुछ बदलता है।

### समस्या निवारण

* **साइन-इन विफल होता है या लूप में चला जाता है।** पहले उसी ब्राउज़र में [business.didit.me](https://business.didit.me) पर लॉग इन करें, फिर **Add & authorize** पर दोबारा क्लिक करें।
* **एक टूल `missing_scope` के साथ उत्तर देता है।** उस संगठन में आपकी भूमिका में वह अनुमति नहीं है। देखें [roles and permissions](https://docs.didit.me/hi/integration/mcp/authentication.md#भूमिकाएँ-और-अनुमतियाँ)।
* **webhook फ़ंक्शन `401` लौटाता है।** जाँचें कि `DIDIT_WEBHOOK_SECRET` उसी गंतव्य का सीक्रेट है जो webhook भेजता है, कि फ़ंक्शन `verify_jwt = false` के साथ डिप्लॉय हुआ है, और कि वह बॉडी को किसी भी पार्सिंग या री-एन्कोडिंग से पहले `req.arrayBuffer()` से पढ़ता है। टाइमस्टैम्प जाँच पर `401` का अर्थ है कि डिलीवरी पाँच मिनट से पुरानी है, या सर्वर की घड़ी सही नहीं है।
* **`didit-create-session` `409` लौटाता है।** Didit बताता है कि उपयोगकर्ता का ट्रैक किया गया सत्र लाइव में स्वीकृत हो चुका है। पेज उस पंक्ति को फिर से पढ़ता है, जिसे webhook अपडेट करता है।
* **`didit-create-session` `502` लौटाता है।** Didit तक पहुँचा नहीं जा सका, या किसी अधूरे सत्र का फिर से शुरू करने वाला कोई लिंक नहीं है। कुछ नया नहीं बनता; फिर से प्रयास करें।
* **सत्र अनुरोध `callback` पर `400` लौटाता है।** अपने ऐप का पता एप्लिकेशन के अनुमति प्राप्त डोमेन में जोड़ें, या `APP_URL` जाँचें।

***

## अगले चरण

> [card] [Webhooks](https://docs.didit.me/hi/integration/webhooks.md)
>
> हर इवेंट, payload फ़ील्ड और हस्ताक्षर हेडर।

> [card] [सत्र बनाएँ](https://docs.didit.me/hi/sessions-api/create-session.md)
>
> सभी अनुरोध फ़ील्ड, जैसे अपेक्षित विवरण और मेटाडेटा।

> [card] [MCP टूल संदर्भ](https://docs.didit.me/hi/integration/mcp/tools.md)
>
> Lovable के एजेंट द्वारा कॉल किए जा सकने वाले हर टूल का विवरण, एक-एक करके।

> [card] [मूल्य निर्धारण](https://docs.didit.me/hi/getting-started/pricing.md)
>
> आपके वर्कफ़्लो में हर जाँच की लागत।


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.