Welcome! Follow these steps to set up the project environment and start developing.
This demo is a vanilla implementation of Didit Identity Verification
Begin by cloning the repository to your local machine. Open a terminal and run:
git clone https://github.com/didit-protocol/didit-full-demo.gitNavigate into the project directory and install its dependencies:
cd didit-full-demo
npm installBefore running the application, you'll need to get some environment variables:
- Visit https://business.didit.me to obtain your
API_KEY, andSHARED_SECRET_KEY(for handling webhooks). - In the application's advanced settings, correctly configure
WEBHOOK_URLto point to your server. For development purposes, you might use:WEBHOOK_URL=https://yourapp.com/api/webhook
Duplicate the .env.example file, rename the duplicate to .env, and fill in the environment variables you obtained from the step above. Your .env file will look something like this:
API_KEY=<YourApiKey>
SHARED_SECRET_KEY=<YourSharedSecretKey>
VERIFICATION_WORKFLOW_ID=<YourVerificationWorkflowId>
# Add any other environment variables as needed.
This demo uses SQLite locally for simplicity. The User model in schema.prisma reflects a real-world application with verification features. Let's break down the key components:
-
User Model:
model User { id String @id @default(cuid()) name String? email String @unique emailVerified DateTime? image String? password String isVerified Boolean @default(false) dateOfBirth DateTime? documentExpiresAt DateTime? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt // Relations sessions Session[] accounts Account[] verificationSessions VerificationSession[] @@map("users") }
isVerified: This Boolean field indicates whether the user has completed the verification process. It defaults tofalsefor new users.dateOfBirthanddocumentExpiresAt: These fields can store information collected during the verification process.verificationSessions: This is a one-to-many relation with theVerificationSessionmodel, allowing a user to have multiple verification attempts.
-
VerificationSession Model:
model VerificationSession { id String @id @default(cuid()) userId String sessionId String @unique status String @default("NOT_STARTED") createdAt DateTime @default(now()) updatedAt DateTime @updatedAt // Relations user User @relation(fields: [userId], references: [id], onDelete: Cascade) @@map("verification_sessions") }
- This model represents individual verification attempts.
status: Tracks the progress of each verification session (e.g., "Not Started", "In Progress", "Approved", "Declined", "In Review", "Expired", "Abandoned", "KYC Expired").sessionId: A unique identifier for each verification session, which can be used to link with external verification service data.
-
Typical Verification Flow:
- When a user initiates verification, a new
VerificationSessionis created with status "NOT_STARTED". - As the user progresses through verification, the status is updated (e.g., to "In Progress"). This update is generally done by the webhook received from Didit.
- Upon successful completion, the status is set to "Approved", and the
User.isVerifiedis set totrue. - Additional user information (like
dateOfBirthanddocumentExpiresAt) can be updated based on the verification results.
- When a user initiates verification, a new
-
Generate Prisma Client and Run Migrations: After understanding the model, generate the Prisma client and run migrations to set up your database schema:
npx prisma generate npx prisma migrate dev --name init
These commands will create your database schema based on the Prisma models and generate the Prisma Client, which you'll use to interact with your database in your application code.
-
Using the Models in Your Application:
- When a user signs up, create a
Userrecord withisVerifiedset tofalse. - Implement a verification flow where you create a
VerificationSessionwhen the user starts the process. - Update the
VerificationSessionstatus as the user progresses. - Once verification is complete, update both the
VerificationSessionstatus and theUser.isVerifiedfield. - Use the
isVerifiedfield to control access to certain parts of your application that require verified users.
- When a user signs up, create a
This setup allows for a flexible and trackable verification process, enabling you to manage multiple verification attempts per user and maintain a clear record of each user's verification status.
Finally, launch the development server. Open your browser and navigate to http://localhost:3000 to view the application:
npm run devInstall ngrok or othher webhook tunnel package.
sudo snap install ngrokAuthenticate using ngrok token
ngrok config add-authtoken YOUR_AUTH_TOKENExpose your local server using ngrok
ngrok http 3000Copy the public URL into the webhook url in app settings of Didit business console adding the path /api/verification/webhook (for this demo)
You're now ready to start developing with the project setup! For more detailed documentation or troubleshooting tips, refer to the official documentation or the README.md file within the project repository.