diff --git a/.gitignore b/Code/.gitignore
similarity index 100%
rename from .gitignore
rename to Code/.gitignore
diff --git a/Code/README.md b/Code/README.md
new file mode 100644
index 0000000..446673a
--- /dev/null
+++ b/Code/README.md
@@ -0,0 +1,142 @@
+# SIH-2025
+Agri-Trace Odisha Development Plan
+
+## 1\. Project Overview
+
+**Project Name:** Agri-Trace Odisha
+**Objective:** To design, develop, and deploy a blockchain-based supply chain transparency system for agricultural produce in Odisha. The platform will leverage Hyperledger Fabric to create an immutable, transparent, and auditable record of produce from farm to consumer, aiming to ensure fair pricing for farmers, reduce fraud, and enhance food safety.
+
+This document outlines the comprehensive development plan, technology stack, architecture, phased rollout strategy, and key milestones for the successful implementation of the pilot program.
+
+-----
+
+## 2\. Technology Stack
+
+The platform will be built on a modular, enterprise-grade technology stack designed for security, scalability, and performance.[1, 2]
+
+| Layer | Technology | Rationale |
+| :--- | :--- | :--- |
+| **Blockchain** | **Hyperledger Fabric v2.x** | Permissioned network ideal for a government-led consortium, offering data privacy via channels, high performance, and no cryptocurrency/gas fees.[3, 1] |
+| **Smart Contracts** | **Go (Chaincode)** | High performance, strong typing, and seamless integration with Fabric's architecture.[4, 5] |
+| **Backend API** | **Node.js (Express.js)** | Efficiently handles I/O operations and has robust SDK support for Hyperledger Fabric, facilitating communication between the frontend and the blockchain.[5] |
+| **Database** | **CouchDB** | Serves as the state database for Fabric, enabling rich queries on ledger data, which is useful for dashboards and analytics.[6, 7] |
+| **File Storage** | **IPFS (InterPlanetary File System)** | For decentralized, tamper-proof storage of off-chain data like quality certificates and images. The hash is stored on-chain for verification.[8] |
+| **Frontend (Web)** | **React.js** | For building the responsive and data-rich dashboards for government officials, FPOs, and other business stakeholders. |
+| **Frontend (Mobile)** | **React Native / Flutter** | For creating a cross-platform mobile app for farmers that is simple, intuitive, works on low-cost devices, and supports the Odia language. |
+| **Deployment** | **Docker & Kubernetes** | For containerizing all network components and applications, ensuring consistent environments and scalable deployment on a cloud platform.[9] |
+| **Cloud Provider** | **AWS / Azure / IBM Cloud** | Utilizing a managed blockchain service (BaaS) to reduce infrastructure overhead and convert capital expenditure to a predictable operational cost.[10, 11, 12] |
+
+-----
+
+## 3\. High-Level Architecture
+
+The system is a permissioned consortium network where each participating organization (e.g., Dept. of Agriculture, FPOs, Processors) is a member.[13, 14]
+
+1. **Consortium & Identity:** The Department of Agriculture & Farmers' Empowerment will act as the network administrator. Each organization will have its own Certificate Authority (CA) to issue digital identities (x.509 certificates) to its users and nodes.[15, 16]
+2. **Network Components:**
+ * **Peer Nodes:** Hosted by major organizations. They maintain the ledger and run chaincode. Roles include Endorsing Peers (simulating transactions) and Committing Peers (validating and writing blocks).[15, 14]
+ * **Ordering Service:** Managed by a neutral group of government entities using the Raft consensus algorithm to order transactions into blocks.[17, 18]
+ * **Channels:** Private sub-networks will be created for confidential transactions between specific parties (e.g., an FPO and a single buyer), ensuring data privacy. A general channel will exist for public data.[19, 20]
+3. **Transaction Flow (Execute-Order-Validate):**
+ * A client application (e.g., farmer's mobile app) signs and sends a transaction proposal to endorsing peers.[21]
+ * Endorsing peers execute the chaincode, verify the request, and sign the result.[18, 21]
+ * The client collects endorsements and submits the transaction to the Ordering Service.
+ * The Ordering Service creates a block of ordered transactions and delivers it to all peers on the channel.
+ * Committing peers validate the block against endorsement policies and commit it to their local ledger.[21, 22]
+
+-----
+
+## 4\. Development Plan: Phased Sprints
+
+The development will follow an agile methodology, broken down into four main phases.
+
+### **Phase 1: Foundation & Core Blockchain Logic
+
+*Goal: Establish the core blockchain network and business logic.*
+
+ * **Sprint 1: Network Setup & Configuration**
+ * [ ] Provision cloud infrastructure using a BaaS provider.[23]
+ * [ ] Configure the network topology (organizations, CAs, orderers, peers).
+ * [ ] Generate cryptographic materials and identities for pilot organizations.
+ * [ ] Set up the initial channel configuration.
+ * **Sprint 2: Chaincode Development (Part 1)**
+ * [ ] Design the core asset data structure (e.g., `ProduceBatch`).
+ * [ ] Implement `createAsset` function for registering new harvests.
+ * [ ] Implement `getAssetHistory` function for traceability queries.
+ * [ ] Write unit tests for all chaincode functions.
+ * **Sprint 3: Chaincode Development (Part 2)**
+ * [ ] Implement `transferOwnership` function with endorsement policies requiring signatures from both buyer and seller.
+ * [ ] Implement `updateAssetStatus` for logistical tracking.
+ * [ ] Design and implement Private Data Collections (PDCs) for sensitive data like pricing.[24, 25]
+ * **Sprint 4: API Layer & SDK Integration**
+ * [ ] Develop a secure RESTful API service (Node.js) to interact with the blockchain.
+ * [ ] Create endpoints for all chaincode functions (`/create`, `/transfer`, `/query`).
+ * [ ] Integrate the Hyperledger Fabric SDK for Go/Node.js to manage identities and submit transactions.
+
+### **Phase 2: Application & UI/UX Development
+
+*Goal: Build user-facing applications for all key stakeholders.*
+
+ * **Sprint 5: Farmer Mobile App (MVP)**
+ * [ ] UI/UX design focused on simplicity, icon-driven navigation, and Odia language support.[26, 27]
+ * [ ] Develop user registration and login flow.
+ * [ ] Implement the "Register New Harvest" feature, connecting to the backend API.
+ * **Sprint 6: QR Code Integration & Mobile App Features**
+ * [ ] Integrate QR code generation upon successful asset creation.
+ * [ ] Implement QR code scanning for asset lookup and ownership transfer.
+ * [ ] Develop "My Batches" and "Sales History" views.
+ * **Sprint 7: Stakeholder Web Portal (Government & Business)**
+ * [ ] UI/UX design for a data-rich, desktop-first dashboard.[28]
+ * [ ] Develop role-based access control (Admin, FPO Manager, Distributor).
+ * [ ] Implement a real-time map view for tracking produce movement.
+ * **Sprint 8: Web Portal Features & Analytics**
+ * [ ] Develop asset search and detailed traceability view.
+ * [ ] Create initial analytics dashboards (e.g., volume by district, price trends).
+ * [ ] Implement user management functionality for the network administrator.
+
+### **Phase 3: Integration, Testing & Security
+
+*Goal: Ensure all components work together seamlessly and securely.*
+
+ * **Sprint 9: End-to-End Integration Testing**
+ * [ ] Integrate mobile and web frontends with the backend API and blockchain network.
+ * [ ] Conduct full transaction lifecycle testing (from farmer creation to retailer receipt).
+ * [ ] Test private data functionality to ensure confidentiality.
+ * **Sprint 10: Performance & Security**
+ * [ ] Conduct load testing to measure transaction throughput (TPS) and latency.[29, 7]
+ * [ ] Perform a security audit of the chaincode and APIs.
+ * [ ] Implement robust error handling and logging across all layers.[18]
+ * **Sprint 11: User Acceptance Testing (UAT)**
+ * [ ] Deploy the platform to a staging environment.
+ * [ ] Conduct UAT with selected pilot users (farmers, FPO managers).
+ * [ ] Gather feedback and iterate on UI/UX based on user input.[27]
+
+### **Phase 4: Deployment & Pilot Launch
+
+*Goal: Launch the pilot program and provide ongoing support.*
+
+ * **Sprint 12: Production Deployment & Go-Live**
+ * [ ] Prepare and deploy the full application stack to the production environment.
+ * [ ] Onboard all pilot program participants and conduct final training sessions.
+ * [ ] **Official Pilot Launch.**
+ * [ ] Establish a user support system (helpline, field support).
+ * [ ] Begin monitoring system performance and user activity KPIs.
+
+-----
+
+## 5\. Risk Assessment & Mitigation
+
+| Risk Category | Description | Mitigation Strategy |
+| :--- | :--- | :--- |
+| **Adoption Risk** | Farmers and other stakeholders may resist adopting a new, complex technology due to low digital literacy or lack of trust.[30, 31] | - **UI/UX:** Design an extremely simple, icon-based mobile app in the Odia language.[26] \
- **Training:** Implement a comprehensive, hands-on training program leveraging government extension officers.[32] \
- **Incentives:** Clearly demonstrate the primary benefit: faster, fairer payments. |
+| **Technical Risk** | Scalability issues or bugs in the smart contracts could disrupt the supply chain.[33, 34] | - **Phased Rollout:** Start with a limited pilot to identify and fix issues before a state-wide launch. \
- **Testing:** Conduct rigorous unit, integration, and performance testing. \
- **Security Audit:** Engage third-party experts to audit the chaincode for vulnerabilities.[35] |
+| **Governance Risk** | Lack of clear rules or disputes between consortium members could stall the project.[36] | - **Steering Committee:** Establish the "Odisha Blockchain for Agriculture (OBA)" Steering Committee from the outset to define policies and resolve disputes. \
- **Clear Policies:** Define endorsement policies and channel access rules in the network configuration. |
+| **Cost Risk** | Development and infrastructure costs could exceed the budget.[37, 38] | - **BaaS Model:** Use a managed blockchain service to have predictable, operational costs instead of large upfront capital costs.[39, 40] \
- **MVP Focus:** Focus the pilot on core features to deliver value quickly and avoid scope creep. |
+
+-----
+
+## 6\. Future Enhancements (Post-Pilot)
+
+ * **Digital Payment Integration:** Integrate with UPI gateways to trigger automatic payments to farmers upon successful ownership transfer, using the blockchain transaction as a verifiable trigger.[9, 41]
+ * **AI & Data Analytics:** Leverage the trusted, immutable data on the blockchain to build AI models for demand forecasting, logistics optimization, and predictive market intelligence.[42, 43]
+ * **IoT Integration:** Integrate with IoT sensors in warehouses and transport vehicles to automatically record temperature and humidity data on the blockchain for high-value goods.[44]
diff --git a/agri/README.md b/Code/agri/README.md
similarity index 100%
rename from agri/README.md
rename to Code/agri/README.md
diff --git a/agri/foundry.toml b/Code/agri/foundry.toml
similarity index 100%
rename from agri/foundry.toml
rename to Code/agri/foundry.toml
diff --git a/agri/out/Agri.sol/Agri.json b/Code/agri/out/Agri.sol/Agri.json
similarity index 100%
rename from agri/out/Agri.sol/Agri.json
rename to Code/agri/out/Agri.sol/Agri.json
diff --git a/agri/out/Agri.t.sol/AgriTest.json b/Code/agri/out/Agri.t.sol/AgriTest.json
similarity index 100%
rename from agri/out/Agri.t.sol/AgriTest.json
rename to Code/agri/out/Agri.t.sol/AgriTest.json
diff --git a/agri/out/Base.sol/CommonBase.json b/Code/agri/out/Base.sol/CommonBase.json
similarity index 100%
rename from agri/out/Base.sol/CommonBase.json
rename to Code/agri/out/Base.sol/CommonBase.json
diff --git a/agri/out/Base.sol/ScriptBase.json b/Code/agri/out/Base.sol/ScriptBase.json
similarity index 100%
rename from agri/out/Base.sol/ScriptBase.json
rename to Code/agri/out/Base.sol/ScriptBase.json
diff --git a/agri/out/Base.sol/TestBase.json b/Code/agri/out/Base.sol/TestBase.json
similarity index 100%
rename from agri/out/Base.sol/TestBase.json
rename to Code/agri/out/Base.sol/TestBase.json
diff --git a/agri/out/IMulticall3.sol/IMulticall3.json b/Code/agri/out/IMulticall3.sol/IMulticall3.json
similarity index 100%
rename from agri/out/IMulticall3.sol/IMulticall3.json
rename to Code/agri/out/IMulticall3.sol/IMulticall3.json
diff --git a/agri/out/StdAssertions.sol/StdAssertions.json b/Code/agri/out/StdAssertions.sol/StdAssertions.json
similarity index 100%
rename from agri/out/StdAssertions.sol/StdAssertions.json
rename to Code/agri/out/StdAssertions.sol/StdAssertions.json
diff --git a/agri/out/StdChains.sol/StdChains.json b/Code/agri/out/StdChains.sol/StdChains.json
similarity index 100%
rename from agri/out/StdChains.sol/StdChains.json
rename to Code/agri/out/StdChains.sol/StdChains.json
diff --git a/agri/out/StdCheats.sol/StdCheats.json b/Code/agri/out/StdCheats.sol/StdCheats.json
similarity index 100%
rename from agri/out/StdCheats.sol/StdCheats.json
rename to Code/agri/out/StdCheats.sol/StdCheats.json
diff --git a/agri/out/StdCheats.sol/StdCheatsSafe.json b/Code/agri/out/StdCheats.sol/StdCheatsSafe.json
similarity index 100%
rename from agri/out/StdCheats.sol/StdCheatsSafe.json
rename to Code/agri/out/StdCheats.sol/StdCheatsSafe.json
diff --git a/agri/out/StdConstants.sol/StdConstants.json b/Code/agri/out/StdConstants.sol/StdConstants.json
similarity index 100%
rename from agri/out/StdConstants.sol/StdConstants.json
rename to Code/agri/out/StdConstants.sol/StdConstants.json
diff --git a/agri/out/StdError.sol/stdError.json b/Code/agri/out/StdError.sol/stdError.json
similarity index 100%
rename from agri/out/StdError.sol/stdError.json
rename to Code/agri/out/StdError.sol/stdError.json
diff --git a/agri/out/StdInvariant.sol/StdInvariant.json b/Code/agri/out/StdInvariant.sol/StdInvariant.json
similarity index 100%
rename from agri/out/StdInvariant.sol/StdInvariant.json
rename to Code/agri/out/StdInvariant.sol/StdInvariant.json
diff --git a/agri/out/StdJson.sol/stdJson.json b/Code/agri/out/StdJson.sol/stdJson.json
similarity index 100%
rename from agri/out/StdJson.sol/stdJson.json
rename to Code/agri/out/StdJson.sol/stdJson.json
diff --git a/agri/out/StdMath.sol/stdMath.json b/Code/agri/out/StdMath.sol/stdMath.json
similarity index 100%
rename from agri/out/StdMath.sol/stdMath.json
rename to Code/agri/out/StdMath.sol/stdMath.json
diff --git a/agri/out/StdStorage.sol/stdStorage.json b/Code/agri/out/StdStorage.sol/stdStorage.json
similarity index 100%
rename from agri/out/StdStorage.sol/stdStorage.json
rename to Code/agri/out/StdStorage.sol/stdStorage.json
diff --git a/agri/out/StdStorage.sol/stdStorageSafe.json b/Code/agri/out/StdStorage.sol/stdStorageSafe.json
similarity index 100%
rename from agri/out/StdStorage.sol/stdStorageSafe.json
rename to Code/agri/out/StdStorage.sol/stdStorageSafe.json
diff --git a/agri/out/StdStyle.sol/StdStyle.json b/Code/agri/out/StdStyle.sol/StdStyle.json
similarity index 100%
rename from agri/out/StdStyle.sol/StdStyle.json
rename to Code/agri/out/StdStyle.sol/StdStyle.json
diff --git a/agri/out/StdToml.sol/stdToml.json b/Code/agri/out/StdToml.sol/stdToml.json
similarity index 100%
rename from agri/out/StdToml.sol/stdToml.json
rename to Code/agri/out/StdToml.sol/stdToml.json
diff --git a/agri/out/StdUtils.sol/StdUtils.json b/Code/agri/out/StdUtils.sol/StdUtils.json
similarity index 100%
rename from agri/out/StdUtils.sol/StdUtils.json
rename to Code/agri/out/StdUtils.sol/StdUtils.json
diff --git a/agri/out/Test.sol/Test.json b/Code/agri/out/Test.sol/Test.json
similarity index 100%
rename from agri/out/Test.sol/Test.json
rename to Code/agri/out/Test.sol/Test.json
diff --git a/agri/out/Vm.sol/Vm.json b/Code/agri/out/Vm.sol/Vm.json
similarity index 100%
rename from agri/out/Vm.sol/Vm.json
rename to Code/agri/out/Vm.sol/Vm.json
diff --git a/agri/out/Vm.sol/VmSafe.json b/Code/agri/out/Vm.sol/VmSafe.json
similarity index 100%
rename from agri/out/Vm.sol/VmSafe.json
rename to Code/agri/out/Vm.sol/VmSafe.json
diff --git a/agri/out/build-info/ca0f9a4b2a33318c.json b/Code/agri/out/build-info/ca0f9a4b2a33318c.json
similarity index 100%
rename from agri/out/build-info/ca0f9a4b2a33318c.json
rename to Code/agri/out/build-info/ca0f9a4b2a33318c.json
diff --git a/agri/out/console.sol/console.json b/Code/agri/out/console.sol/console.json
similarity index 100%
rename from agri/out/console.sol/console.json
rename to Code/agri/out/console.sol/console.json
diff --git a/agri/out/safeconsole.sol/safeconsole.json b/Code/agri/out/safeconsole.sol/safeconsole.json
similarity index 100%
rename from agri/out/safeconsole.sol/safeconsole.json
rename to Code/agri/out/safeconsole.sol/safeconsole.json
diff --git a/agri/script/Counter.s.sol b/Code/agri/script/Counter.s.sol
similarity index 100%
rename from agri/script/Counter.s.sol
rename to Code/agri/script/Counter.s.sol
diff --git a/agri/src/Agri.sol b/Code/agri/src/Agri.sol
similarity index 100%
rename from agri/src/Agri.sol
rename to Code/agri/src/Agri.sol
diff --git a/agri/test/Agri.t.sol b/Code/agri/test/Agri.t.sol
similarity index 100%
rename from agri/test/Agri.t.sol
rename to Code/agri/test/Agri.t.sol
diff --git a/backend/.gitignore b/Code/backend/.gitignore
similarity index 100%
rename from backend/.gitignore
rename to Code/backend/.gitignore
diff --git a/backend/lib/prismaClient.js b/Code/backend/lib/prismaClient.js
similarity index 100%
rename from backend/lib/prismaClient.js
rename to Code/backend/lib/prismaClient.js
diff --git a/backend/package-lock.json b/Code/backend/package-lock.json
similarity index 100%
rename from backend/package-lock.json
rename to Code/backend/package-lock.json
diff --git a/backend/package.json b/Code/backend/package.json
similarity index 100%
rename from backend/package.json
rename to Code/backend/package.json
diff --git a/backend/prisma/migrations/20250911175519_init/migration.sql b/Code/backend/prisma/migrations/20250911175519_init/migration.sql
similarity index 100%
rename from backend/prisma/migrations/20250911175519_init/migration.sql
rename to Code/backend/prisma/migrations/20250911175519_init/migration.sql
diff --git a/backend/prisma/migrations/migration_lock.toml b/Code/backend/prisma/migrations/migration_lock.toml
similarity index 100%
rename from backend/prisma/migrations/migration_lock.toml
rename to Code/backend/prisma/migrations/migration_lock.toml
diff --git a/backend/prisma/schema.prisma b/Code/backend/prisma/schema.prisma
similarity index 100%
rename from backend/prisma/schema.prisma
rename to Code/backend/prisma/schema.prisma
diff --git a/backend/server.js b/Code/backend/server.js
similarity index 100%
rename from backend/server.js
rename to Code/backend/server.js
diff --git a/frontend/.gitignore b/Code/frontend/.gitignore
similarity index 100%
rename from frontend/.gitignore
rename to Code/frontend/.gitignore
diff --git a/frontend/README.md b/Code/frontend/README.md
similarity index 100%
rename from frontend/README.md
rename to Code/frontend/README.md
diff --git a/frontend/eslint.config.js b/Code/frontend/eslint.config.js
similarity index 100%
rename from frontend/eslint.config.js
rename to Code/frontend/eslint.config.js
diff --git a/frontend/index.html b/Code/frontend/index.html
similarity index 100%
rename from frontend/index.html
rename to Code/frontend/index.html
diff --git a/frontend/package-lock.json b/Code/frontend/package-lock.json
similarity index 100%
rename from frontend/package-lock.json
rename to Code/frontend/package-lock.json
diff --git a/frontend/package.json b/Code/frontend/package.json
similarity index 96%
rename from frontend/package.json
rename to Code/frontend/package.json
index 6890460..26891ea 100644
--- a/frontend/package.json
+++ b/Code/frontend/package.json
@@ -10,6 +10,7 @@
"preview": "vite preview"
},
"dependencies": {
+ "@clerk/clerk-react": "^5.0.0",
"@prisma/client": "^6.16.1",
"@tailwindcss/vite": "^4.1.13",
"bip39": "^3.1.0",
diff --git a/frontend/public/vite.svg b/Code/frontend/public/vite.svg
similarity index 100%
rename from frontend/public/vite.svg
rename to Code/frontend/public/vite.svg
diff --git a/frontend/public/wheat.png b/Code/frontend/public/wheat.png
similarity index 100%
rename from frontend/public/wheat.png
rename to Code/frontend/public/wheat.png
diff --git a/frontend/src/App.css b/Code/frontend/src/App.css
similarity index 100%
rename from frontend/src/App.css
rename to Code/frontend/src/App.css
diff --git a/frontend/src/App.jsx b/Code/frontend/src/App.jsx
similarity index 100%
rename from frontend/src/App.jsx
rename to Code/frontend/src/App.jsx
diff --git a/frontend/src/assets/img.jpg b/Code/frontend/src/assets/img.jpg
similarity index 100%
rename from frontend/src/assets/img.jpg
rename to Code/frontend/src/assets/img.jpg
diff --git a/frontend/src/assets/react.svg b/Code/frontend/src/assets/react.svg
similarity index 100%
rename from frontend/src/assets/react.svg
rename to Code/frontend/src/assets/react.svg
diff --git a/frontend/src/components/ChatbotSider.jsx b/Code/frontend/src/components/ChatbotSider.jsx
similarity index 100%
rename from frontend/src/components/ChatbotSider.jsx
rename to Code/frontend/src/components/ChatbotSider.jsx
diff --git a/frontend/src/components/ethWallet.jsx b/Code/frontend/src/components/ethWallet.jsx
similarity index 100%
rename from frontend/src/components/ethWallet.jsx
rename to Code/frontend/src/components/ethWallet.jsx
diff --git a/frontend/src/components/footer.jsx b/Code/frontend/src/components/footer.jsx
similarity index 100%
rename from frontend/src/components/footer.jsx
rename to Code/frontend/src/components/footer.jsx
diff --git a/frontend/src/components/ipfsupload.jsx b/Code/frontend/src/components/ipfsupload.jsx
similarity index 100%
rename from frontend/src/components/ipfsupload.jsx
rename to Code/frontend/src/components/ipfsupload.jsx
diff --git a/frontend/src/components/navbar.jsx b/Code/frontend/src/components/navbar.jsx
similarity index 100%
rename from frontend/src/components/navbar.jsx
rename to Code/frontend/src/components/navbar.jsx
diff --git a/frontend/src/components/popup.jsx b/Code/frontend/src/components/popup.jsx
similarity index 100%
rename from frontend/src/components/popup.jsx
rename to Code/frontend/src/components/popup.jsx
diff --git a/Code/frontend/src/components/verify.jsx b/Code/frontend/src/components/verify.jsx
new file mode 100644
index 0000000..fb91213
--- /dev/null
+++ b/Code/frontend/src/components/verify.jsx
@@ -0,0 +1,181 @@
+import React, { useState } from "react";
+import {
+ useSignIn,
+ useClerk,
+ useSession,
+} from "@clerk/clerk-react";
+import { useNavigate } from "react-router-dom";
+
+const Verify = ({ onVerificationSuccess }) => {
+ const { signIn } = useSignIn();
+ const { isLoaded, isSignedIn } = useSession();
+ const clerk = useClerk();
+ const navigate = useNavigate();
+
+ const [phone, setPhone] = useState("");
+ const [smsCode, setSmsCode] = useState("");
+ const [loading, setLoading] = useState(false);
+ const [resending, setResending] = useState(false);
+ const [isSent, setIsSent] = useState(false);
+
+ // If already signed in, navigate to the dashboard or home page
+ if (isLoaded && isSignedIn) {
+ navigate("/");
+ }
+
+ // Handle phone number submission and send OTP
+ const handleSendOTP = async (e) => {
+ e.preventDefault();
+ if (!phone.trim()) {
+ alert("Please enter a valid phone number");
+ return;
+ }
+ setResending(true);
+ try {
+ // Create or update a sign-in attempt with the phone number
+ const res = await signIn.create({
+ strategy: "phone_code",
+ identifier: phone,
+ });
+
+ // After successful creation, request the phone code
+ await res.prepareFirstFactor({
+ strategy: "phone_code",
+ });
+
+ setIsSent(true);
+ alert("Verification code sent!");
+ } catch (err) {
+ console.error("Error sending OTP:", err.errors?.[0]?.longMessage || err.message);
+ alert(err.errors?.[0]?.longMessage || "Error sending OTP. Please try again.");
+ } finally {
+ setResending(false);
+ }
+ };
+
+ // Handle OTP verification
+ const handleVerifyOTP = async (e) => {
+ e.preventDefault();
+ setLoading(true);
+ try {
+ // Attempt to authenticate the user with the received code
+ const completeSignIn = await signIn.attemptFirstFactor({
+ strategy: "phone_code",
+ code: smsCode,
+ });
+ // If successful, set the active session and call success callback
+ if (completeSignIn.status === "complete") {
+ await clerk.setActive({ session: completeSignIn.createdSessionId });
+ localStorage.setItem("verified", "true");
+ onVerificationSuccess && onVerificationSuccess();
+ } else {
+ console.error("Verification failed:", completeSignIn);
+ const handleSubmit = (e) => {
+ e.preventDefault();
+ if (smsCode.length === 6) verifyOTP();
+
+ };
+
+ const handlePhoneChange = (e) => {
+ setPhone(e.target.value.replace(/[^\d+\-\s()]/g, ""));
+ };
+ return (
+
+ {isSent ? "Enter the verification code sent to your phone." : "Enter your phone number to receive a verification code."} +
+- Enter your phone number and verification code -
-