<?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: Ahmet Akinsel</title>
    <description>The latest articles on DEV Community by Ahmet Akinsel (@ahmetakinsel).</description>
    <link>https://dev.to/ahmetakinsel</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%2F814268%2F30f2762f-cfbd-4413-90a7-afd3ae4be614.jpeg</url>
      <title>DEV Community: Ahmet Akinsel</title>
      <link>https://dev.to/ahmetakinsel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ahmetakinsel"/>
    <language>en</language>
    <item>
      <title>Integrating Google reCAPTCHA</title>
      <dc:creator>Ahmet Akinsel</dc:creator>
      <pubDate>Thu, 16 Nov 2023 11:08:23 +0000</pubDate>
      <link>https://dev.to/ahmetakinsel/integrating-google-recaptcha-2nmh</link>
      <guid>https://dev.to/ahmetakinsel/integrating-google-recaptcha-2nmh</guid>
      <description>&lt;p&gt;To integrate Google reCAPTCHA in your project, you need to perform the following steps for both the API and frontend:&lt;/p&gt;

&lt;p&gt;1-Set up reCAPTCHA API:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Go to the Google reCAPTCHA website (&lt;a href="https://www.google.com/recaptcha"&gt;https://www.google.com/recaptcha&lt;/a&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sign in with your Google account. (&lt;a href="mailto:youremail@gmai.com"&gt;youremail@gmai.com&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Register your website and obtain the reCAPTCHA Site Key and Secret Key.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2-Install the necessary dependencies:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install the react-google-recaptcha package for the frontend using npm or yarn.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;3-Frontend Integration:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Import the required components from the installed package: ReCAPTCHA from "react-google-recaptcha".&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a reference using useRef to access the reCAPTCHA component.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set up the necessary states to manage the form data, validation, and reCAPTCHA token.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Render the reCAPTCHA component using the obtained Site Key from the API.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Implement event handlers to handle form submission and user actions (e.g., toggling password visibility).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Validate the form fields and display error messages if necessary.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use the getValue() method of the reCAPTCHA reference to get the user's response and set the token state.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pass the obtained token along with other form data to your API request.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;4-Backend Integration:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Implement an API endpoint to receive the form data and reCAPTCHA token.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Verify the reCAPTCHA token using the reCAPTCHA Secret Key obtained in step 1.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the token is valid, proceed with processing the form data. Otherwise, return an error.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Please note that the provided code is only the frontend part and assumes you have implemented the backend API separately.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Remember to replace the placeholder "REACT_APP_GOOGLE_RECAPTCHA_SITE_KEY" with the actual Site Key obtained from the Google reCAPTCHA website.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make sure to handle the API request to postUser on your server-side code. You can find the integration example on &lt;code&gt;your-platform-api&lt;/code&gt; and &lt;code&gt;your-platform-fe&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>programming</category>
      <category>javascript</category>
      <category>api</category>
      <category>node</category>
    </item>
    <item>
      <title>How to create a delete endpoint with node.js and MySql</title>
      <dc:creator>Ahmet Akinsel</dc:creator>
      <pubDate>Thu, 31 Mar 2022 07:40:27 +0000</pubDate>
      <link>https://dev.to/ahmetakinsel/how-to-create-a-delete-endpoint-with-nodejs-and-mysql-17bn</link>
      <guid>https://dev.to/ahmetakinsel/how-to-create-a-delete-endpoint-with-nodejs-and-mysql-17bn</guid>
      <description>&lt;p&gt;Define your endpoint on &lt;code&gt;routes.js&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;router.delete( "/delete-user/:userId", authentication, authorise({ roles: [ADMIN] }), deleteUserById );&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;In this endpoint we use url, middlewares and controller.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First define your url,&lt;/li&gt;
&lt;li&gt;Check if the user logged in, (authentication)&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Authorise if user is admin, guest what so ever. (authorise- OPTIONAL)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;define the controller.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Our endpoint deletes user records by user id.That means it checks user's id from req.params, validates it with yup then removes user with action function then it gives the response.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const removeUserById = require("~root/actions/users/removeUserById");
const handleAPIError = require("~root/utils/handleAPIError");
const deleteUserByIdSchema = require("./schemas/deleteUserByIdSchema");

const deleteUserById = async (req, res) =&amp;gt; {
  const { userId } = req.params;

  try {
    await deleteUserByIdSchema.validate(
      { userId },
      {
        abortEarly: false
      }
    );

    await removeUserById({
      userId
    });

    res.status(200).send();

  } catch (err) {
    handleAPIError(res, err);
  }
};

module.exports = deleteUserById;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Quick tip: Controller:"delete" (Controllers always named as CRUD operations. Thats why controllers always named as delete,put,post,get etc.) =&amp;gt; Action:"remove"&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;After creating your controller create your action. Action is an async function. It has &lt;code&gt;userId&lt;/code&gt; as parameter and it returns &lt;code&gt;{deleteUser}&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const deleteUserById = require("./queries/deleteUserById");

const removeUserById = async ({ userId }) =&amp;gt; {
  const deletedUser = await deleteUserById({ userId });
  return { deletedUser };
};

module.exports = removeUserById;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Once you create your action you need a query for it. Create a queries folder inside your &lt;code&gt;removeUserById&lt;/code&gt; folder. We are using MySQL for this project. Basically we need to tell our database that "find the user record associated with user_id  from users table".
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { submitQuery } = require("~root/lib/database");

const deleteUserById = ({ userId }) =&amp;gt; submitQuery`
  DELETE FROM users   
  WHERE user_id = ${userId};
`;

module.exports = deleteUserById;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;After creating your query we can validate the process with yup. Create a &lt;code&gt;schemas&lt;/code&gt; folder inside &lt;code&gt;deleteUserById&lt;/code&gt; folder. You can validate if user_id is number,required?, positive(!-), integer? or has a label("").
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const yup = require("yup");

const deleteCuttingToolByIdSchema = yup.object().shape({
  userId: yup
  .number()
  .required()
  .positive()
  .integer()
  .label("User ID")
  .typeError("User ID must be a number.")
});

 module.exports = deleteCuttingToolByIdSchema
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;After this process your need to play with projects database-schema. In this scenario we have a parent table which is users table. Also there are 2 child tables. That's why we can use &lt;code&gt;ON DELETE CASCADE&lt;/code&gt; command from MySql. This command deletes the record for every records that includes ON CASCADE DELETE command. It follows. That's why we put that command to FOREING KEYs. Below changes should be made to any table which references user_id column.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Test it on Postman by making a call to DELETE /delete-user/1&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>node</category>
      <category>mysql</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>Git/Github workflow and Tips 
</title>
      <dc:creator>Ahmet Akinsel</dc:creator>
      <pubDate>Fri, 25 Feb 2022 08:52:10 +0000</pubDate>
      <link>https://dev.to/ahmetakinsel/gitgithub-workflow-and-tips-1ai3</link>
      <guid>https://dev.to/ahmetakinsel/gitgithub-workflow-and-tips-1ai3</guid>
      <description>&lt;p&gt;This post is written to guide and help the junior software developers. I want to share the useful tips and information I learned about Git/Github during my first 3 months of experience.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Before starting to work, always pull the latest from the master.&lt;/li&gt;
&lt;li&gt;Always work on a separate branch.&lt;/li&gt;
&lt;li&gt;Prevent direct commits, don't &lt;code&gt;git push&lt;/code&gt; straight to the master.&lt;/li&gt;
&lt;li&gt;All commits should be pushed to the master through "pull requests".&lt;/li&gt;
&lt;li&gt;Pay attention to branch naming conventions.&lt;/li&gt;
&lt;li&gt;Write meaningful commit messages. You can use “verb + context” pattern when commenting on descriptions in PRs. e.g: fixed card width.&lt;/li&gt;
&lt;li&gt;Make sure to write a PR description about the work you have done or the problems you encounter.&lt;/li&gt;
&lt;li&gt;Track the PRs that you created. Don’t forget to check all the changes requested and pipelines. Make sure all checks have passed.&lt;/li&gt;
&lt;li&gt;Avoid committing large files. Optimum commit is between 300-500 lines of code.&lt;/li&gt;
&lt;li&gt;Delete outdated branches.&lt;/li&gt;
&lt;li&gt;Always check your github notifications.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Some useful git commands:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git diff&lt;/code&gt; (shows unstaged changes since last commit)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git reset&lt;/code&gt; (undoes git add before commit)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git log&lt;/code&gt; (shows a list of all the commits made to a repository)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git push –no-verify&lt;/code&gt; (uploads local repository content to a remote repository without verification) &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git status&lt;/code&gt; (gives all the necessary information about the current branch)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git branch&lt;/code&gt; (viewing branches)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git branch -r&lt;/code&gt; (shows your remote branches)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git checkout -b &amp;lt;branch-name&amp;gt;&lt;/code&gt; (creates a new branch)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git checkout -&lt;/code&gt; (switches back to previous branch)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git checkout -- .&lt;/code&gt; (cancels all changes for the current branch you're working on)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git reset --hard origin/master&lt;/code&gt; (this commands  basically  forgets everything on your current local branch and makes it exactly the same as the origin/master)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How to merge your current branch with another branch?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Step 1: Commit and push your changes to your current branch.&lt;br&gt;
Step 2: Switch from your current branch to the branch you want to merge.&lt;br&gt;
Step 3: &lt;code&gt;git pull&lt;/code&gt;. Make sure the branch you want to merge  has the latest version before you merge your branches, otherwise you may face conflicts or other problems.&lt;br&gt;
Step 4:&lt;code&gt;git merge &amp;lt;branch-name&amp;gt;&lt;/code&gt; you can merge your feature branch into the branch you want to merge.&lt;br&gt;
Step 5: push your changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to resolve conflicts?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Step1: To resolve a conflict git checkout master and pull the latest.&lt;br&gt;
Step2: &lt;code&gt;git checkout &amp;lt;target branch&amp;gt;&lt;/code&gt;.&lt;br&gt;
Step3: &lt;code&gt;git merge master&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After this process if everything is fine no error message will appear. If it's not, a message will appear that says "This branch has conflicts that must be resolved". In this stage you'll need to fix the conflict manually in Github or your code editor. Open your code editor and accept the current changes (what's on your branch), incoming changes (master) accept one of these options or both according to your needs.&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>career</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
