<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Saksham Negi</title>
    <description>The latest articles on DEV Community by Saksham Negi (@fightclub07).</description>
    <link>https://dev.to/fightclub07</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F728243%2F2e776aac-561e-42f5-9df7-9effac39b4be.png</url>
      <title>DEV Community: Saksham Negi</title>
      <link>https://dev.to/fightclub07</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fightclub07"/>
    <language>en</language>
    <item>
      <title>Implement google reCaptcha v3 in your React and Go application</title>
      <dc:creator>Saksham Negi</dc:creator>
      <pubDate>Wed, 26 Mar 2025 16:21:21 +0000</pubDate>
      <link>https://dev.to/fightclub07/implement-google-recaptcha-v3-in-your-react-and-go-application-341h</link>
      <guid>https://dev.to/fightclub07/implement-google-recaptcha-v3-in-your-react-and-go-application-341h</guid>
      <description>&lt;p&gt;CAPTCHA stands for Completely Automated Public Turing Test to tell Computers and Humans apart. It is a type of security measure which protects your application against bots and helps you detect abusive traffic. Google reCaptcha v3 is a service provided by google which uses risk analysis techniques to detect and block spam traffic without user interaction. Let’s us see how to implement it in React and Go.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;How it works&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The google reCaptcha v3 service gives two keys- a site key and a secret key for validation. The site key is used for token generation in the client side and secret key is used for validation in server side. The token generated using site key is sent to the server for verification. Generally, it is sent during any form submission along with the form values. In the server, the the request is verified using the endpoint:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://www.google.com/recaptcha/api/siteverify
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The secret key stored in server and the token received from client are sent in the body of this request as x-www-form-urlencoded values. It returns an error if the keys or token does not match. In case of successful request, it returns a score between 0.0 and 1.0 where 1.0 indicates a human and 0.0 indicates a bot. The threshold value to block or allow the traffic is set according to the needs of our application. More on this later in the article.&lt;/p&gt;

&lt;h3&gt;
  
  
  Service Setup
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Go to &lt;a href="https://www.google.com/recaptcha/admin/create" rel="noopener noreferrer"&gt;https://www.google.com/recaptcha/admin/create&lt;/a&gt; and register your application.&lt;/li&gt;
&lt;li&gt;Enter your app name in label.&lt;/li&gt;
&lt;li&gt;Select reCaptcha type as Score based (v3).&lt;/li&gt;
&lt;li&gt;Enter your domain name in which your app will be hosted. For local testing, add localhost in it.&lt;/li&gt;
&lt;li&gt;Once you finish, you’ll get the site key and secret key. Copy them both as we will use them later.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Code Setup
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Install react-google-recaptcha-v3 package:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i react-google-recaptcha-v3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Get reCaptcha token and send it to the server:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from "react";
import { GoogleReCaptchaProvider, useGoogleReCaptcha } from "react-google-recaptcha-v3";

const RECAPTCHA_SITE_KEY = "your-site-key"; // Replace with your actual site key

const MyForm = () =&amp;gt; {
  const { executeRecaptcha } = useGoogleReCaptcha();
  const [formData, setFormData] = useState({});

  const handleSubmit = async (e) =&amp;gt; {
    e.preventDefault();
    if (!executeRecaptcha) {
      console.log("reCAPTCHA not loaded yet");
      return;
    }

    // Execute reCAPTCHA to get the token
    const recaptchaToken = await executeRecaptcha("submit");

    // Send form data + token to backend
    const response = await fetch("http://localhost:8080/api/verify-recaptcha", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ ...formData, recaptchaToken }),
    });

    const data = await response.json();
    if (data.success) {
      alert("Form submitted successfully!");
    } else {
      alert("reCAPTCHA verification failed. Please try again.");
    }
  };

  return (
  // your form
    &amp;lt;form onSubmit={handleSubmit}&amp;gt;
      &amp;lt;button type="submit"&amp;gt;Submit&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
  );
};

// Wrap your app with GoogleReCaptchaProvider
const App = () =&amp;gt; (
  &amp;lt;GoogleReCaptchaProvider reCaptchaKey={RECAPTCHA_SITE_KEY}&amp;gt;
    &amp;lt;MyForm /&amp;gt;
  &amp;lt;/GoogleReCaptchaProvider&amp;gt;
);

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Verify the token and process the form submission:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type RecaptchaResponse struct {
    Success bool    `json:"success"`
    Score   float64 `json:"score"`
}

func VerifyRecaptchaToken(token string) error {
    var recaptchaResponse RecaptchaResponse

    secretKey := os.Getenv("RECAPTCHA_SECRET_TOKEN")
    resp, err := http.PostForm("https://www.google.com/recaptcha/api/siteverify",
        url.Values{
            "secret":   {secretKey},
            "response": {token},
        })
    if err != nil {
        return err
    }
    defer resp.Body.Close()

    if err := json.NewDecoder(resp.Body).Decode(&amp;amp;recaptchaResponse); err != nil {
        return err
    }

    thresholdNumber := constant.DEFAULT_RECAPTCHA_THRESHOLD
    // verification failed or score less than set threshold
    if !recaptchaResponse.Success || recaptchaResponse.Score &amp;lt;= thresholdNumber {
        return errors.New("verification failed")
    }

    // process the form submission
    return nil
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Score and Threshold
&lt;/h3&gt;

&lt;p&gt;As we know now, the reCaptcha verification API returns a score. The request is blocked or allowed based on that score and the set threshold. The threshold value is set according to the application. Generally a value of 0.5 as threshold is widely used. It means score less than 0.5 will be marked as a bot and anything greater than that is allowed.&lt;/p&gt;

&lt;p&gt;If the user on the application has logged in, the chances of bot requests become less. In these cases we can set the threshold around ~0.5. If the application has an open form, without authentication, increasing the threshold should be considered — preferably somewhere around ~0.7 as the chances of bot requests are higher.&lt;/p&gt;

&lt;p&gt;The behaviour of the requests with low scores can also be configured. Some common methods of dealing with such requests are OTP/email verification, reCaptcha v2(challenge), manual reviews or blocking them straight away.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;I hope you enjoyed the article, any suggestions/improvements are welcome.&lt;/p&gt;

&lt;p&gt;Reach out to me at &lt;a href="//mailto:sakshamnegi.dev@gmail.com"&gt;sakshamnegi.dev@gmail.com&lt;/a&gt; for any questions, feedback, or collaboration opportunities.&lt;/p&gt;

</description>
      <category>recaptcha</category>
      <category>go</category>
      <category>react</category>
      <category>recaptchav3</category>
    </item>
    <item>
      <title>Database schema design of Splitwise application</title>
      <dc:creator>Saksham Negi</dc:creator>
      <pubDate>Mon, 16 Dec 2024 17:58:54 +0000</pubDate>
      <link>https://dev.to/fightclub07/database-schema-design-of-splitwise-application-2ef0</link>
      <guid>https://dev.to/fightclub07/database-schema-design-of-splitwise-application-2ef0</guid>
      <description>&lt;p&gt;Splitwise gained vast popularity among travellers and friend groups. I built quicksplit, which works like splitwise and I want to share the schema design for a splitwise-like expense sharing and expense management application.&lt;/p&gt;

&lt;p&gt;The application allows users to share expenses in groups and track how much they owe to each other. It enables users to create groups, manage expenses, track debts, and settle payments with ease. Let us have a look on how we can design the database for this.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Project features&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;  User Authentication: Secure registration, login, and logout.&lt;/li&gt;
&lt;li&gt;  Group Management: Create and manage groups with customisable members.&lt;/li&gt;
&lt;li&gt;  Expense Management: Add, categorise, and split expenses among group members.&lt;/li&gt;
&lt;li&gt;  Debt Tracking: Automatic calculation and tracking of balances between users.&lt;/li&gt;
&lt;li&gt;  Settlement and Payment Tracking: Manual recording of settlements and payments.&lt;/li&gt;
&lt;li&gt;  Notifications: Email notifications for group activities like expense creation and for payment reminders.&lt;/li&gt;
&lt;li&gt;  Reporting: Generate and download payments report.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Database design
&lt;/h3&gt;

&lt;p&gt;Let’s dive into the schema of this application. Here is the image for your reference:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmtogf6t4zjofj2f27g3u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmtogf6t4zjofj2f27g3u.png" alt="DB schema diagram" width="800" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Users table:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This contains users information- you can also choose phone number instead of email or even both.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Groups and Members:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The groups table contains the groups and group details. Similarly, the members table contains the members of each group. The created_by in groups references id from users table. In members table, users_id references the id from users table and group_id references id from groups table.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Expenses:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This table tracks the expenses made in each group. It stores expense description, amount and the creator of the expense.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Balances:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This table stores the updated balances among the users. It keeps track of who owes how much to whom. One can find out the amount to be paid between two users in a single query through this table.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Payments:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To record the settlements, we need this table. It stores the payment between two users. It also has a unique &lt;code&gt;payment_id&lt;/code&gt; column so that users can cross check in case of discrepancy.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Reminders(optional):&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This records the payment reminders or notifications sent to the users. This supports the integration of sending payment reminders functionality. Admins can track how many email/mobile notifications were sent successfully and what were it’s results.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;I hope you enjoyed the article, any suggestions/improvements are welcome.&lt;/p&gt;

&lt;p&gt;Reach out to me at &lt;a href="//mailto:sakshamnegi.dev@gmail.com"&gt;sakshamnegi.dev@gmail.com&lt;/a&gt; for any questions, feedback, or collaboration opportunities.&lt;/p&gt;

</description>
      <category>splitwise</category>
      <category>expensemanagement</category>
      <category>database</category>
      <category>schema</category>
    </item>
  </channel>
</rss>
