<?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: Mayank Singh Tomar</title>
    <description>The latest articles on DEV Community by Mayank Singh Tomar (@mstomar698).</description>
    <link>https://dev.to/mstomar698</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%2F844520%2Fb9913015-8bce-4a2e-b278-e5c89c45009d.jpeg</url>
      <title>DEV Community: Mayank Singh Tomar</title>
      <link>https://dev.to/mstomar698</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mstomar698"/>
    <language>en</language>
    <item>
      <title>Responsive ToDo App Using Redis As Main Database</title>
      <dc:creator>Mayank Singh Tomar</dc:creator>
      <pubDate>Sun, 28 Aug 2022 10:26:10 +0000</pubDate>
      <link>https://dev.to/mstomar698/responsive-todo-app-using-redis-as-main-database-4021</link>
      <guid>https://dev.to/mstomar698/responsive-todo-app-using-redis-as-main-database-4021</guid>
      <description>&lt;h3&gt;
  
  
  Overview of My Submission
&lt;/h3&gt;

&lt;p&gt;Here, we are going to make a simple todo-app showing how we can use redis as main db.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For starters in backend server we will be using &lt;strong&gt;&lt;code&gt;express&lt;/code&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;cors&lt;/code&gt;&lt;/strong&gt;,&lt;strong&gt;&lt;code&gt;redis-om&lt;/code&gt;&lt;/strong&gt;. Where:&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;express&lt;/code&gt;&lt;/strong&gt;: Provides basic server for connecting db and frontend.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;cors&lt;/code&gt;&lt;/strong&gt;: Provides connection btw backend and frontend.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;redis-om&lt;/code&gt;&lt;/strong&gt;: It is new library by redis which provides all basic neccessities required in a databse and can be managed and created using redis-cloud.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h6&gt;
  
  
  # Note: See repo on how to setup the basic db and api's.&lt;a href="https://github.com/201B153/ToDo-Using-Redis/blob/master/todo-backend/src/index.js"&gt;Link To Backend&lt;/a&gt;
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;Now lets setup the database:&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Here, we will be using redis cloud db which comes in both free and paid db @&lt;a href="https://redis.com/try-free/?_ga=2.112859588.1175317799.1661010142-187499918.1660282909"&gt;Redis-Cloud&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;For creating a db in redis cloud you just need to signup on #link and create a subscription.&lt;/li&gt;
&lt;li&gt;On creating a subscription redis will provide a db with particular &lt;code&gt;endpoint&lt;/code&gt; and &lt;code&gt;defaultuser&amp;amp;password&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;We just need endpoint and password for accessing the db.&lt;/li&gt;
&lt;li&gt;Then we will create the schema on which the db will work.&lt;/li&gt;
&lt;/ol&gt;

&lt;h6&gt;
  
  
  # Note: See repo on how to setup Schema. &lt;a href="https://github.com/201B153/ToDo-Using-Redis/tree/master/todo-backend/src/schema"&gt;Link To Schema&lt;/a&gt;
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;Later, for frontend we will be using react as framework and bootstrap 5 as styling.&lt;/li&gt;
&lt;/ul&gt;

&lt;h6&gt;
  
  
  # Note: See repo on how to setup Frontend. &lt;a href="https://github.com/201B153/ToDo-Using-Redis/blob/master/todo-frontend/src/App.js"&gt;Link To frontend&lt;/a&gt;
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;The whole process works as:&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Firstly, on initiating the backend we create a server on port &lt;code&gt;8000&lt;/code&gt; which provides access to db and initiates api's.&lt;/li&gt;
&lt;li&gt;On otherhand, the frontend which is initiated on port &lt;code&gt;3000&lt;/code&gt; can call api's to access the db and edit or update it.&lt;/li&gt;
&lt;li&gt;On for checking db we can use RedisInsight which is free to download provided by redis.&lt;/li&gt;
&lt;/ol&gt;

&lt;h6&gt;
  
  
  # Note: RedisInsight keeps db record on local machine. It helps in easy access to db and also it makes db easy to read and modify.&lt;a href="https://redis.com/redis-enterprise/redis-insight/#insight-form"&gt;Link To redisinsight&lt;/a&gt;
&lt;/h6&gt;

&lt;h4&gt;
  
  
  Submission Category: MERN Mavericks
&lt;/h4&gt;

&lt;h4&gt;
  
  
  Following languages are used in this project: &lt;code&gt;JS/Node.js/CSS&lt;/code&gt;.
&lt;/h4&gt;

&lt;h4&gt;
  
  
  Here, you can find complete source code of the project:
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://github.com/201B153/ToDo-Using-Redis"&gt;Link To Source Code&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  The demo app can be seen on:
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://todo-redis.herokuapp.com/"&gt;Link To Demo&lt;/a&gt;&lt;/p&gt;




</description>
      <category>redishackathon</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>SignIn with Google according to new update</title>
      <dc:creator>Mayank Singh Tomar</dc:creator>
      <pubDate>Sat, 16 Jul 2022 10:49:56 +0000</pubDate>
      <link>https://dev.to/mstomar698/signin-with-google-according-to-new-update-21kb</link>
      <guid>https://dev.to/mstomar698/signin-with-google-according-to-new-update-21kb</guid>
      <description>&lt;h2&gt;
  
  
  Since SignIn forms are always first steps that every web developers take let's add Google services to them.
&lt;/h2&gt;

&lt;p&gt;Things we need to do get a Google enabled signin form is just to follows the given steps.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First goto the &lt;a href="https://console.cloud.google.com"&gt;Google Cloud Platform&lt;/a&gt; and create new project or use already created one.&lt;/li&gt;
&lt;li&gt;Move to credentials in APIs &amp;amp; Services which will look something like given below.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iH4F0Jpm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bvtxi4dhohsfk3jdvw31.jpg" alt="A1" width="880" height="468"&gt;
&lt;/li&gt;
&lt;li&gt;Inside configure consent screen select &lt;code&gt;External&lt;/code&gt;  as option and  Click &lt;code&gt;Create&lt;/code&gt;. This will lead us to form which asks for information regarding what you are creating.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pO_BFjqp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5bx9codeq3a9r7xosnid.jpg" alt="A2" width="880" height="419"&gt;
&lt;/li&gt;
&lt;li&gt;Fill the form with proper name and Email make sure you use your GCP mail in the form and click on &lt;code&gt;Save and Continue&lt;/code&gt;; 
you can skip scopes part arrive directly at &lt;code&gt;Test Users&lt;/code&gt; part of the form here you have to &lt;code&gt;add Email&lt;/code&gt; which will we used to check services on localhost.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eqGWrkXf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sxzvduyw9y611c70u9cm.jpg" alt="A3" width="880" height="442"&gt;
&lt;/li&gt;
&lt;li&gt;Now go back to credentials and &lt;code&gt;CREATE CREDENTIALS&lt;/code&gt; for &lt;code&gt;OAuth client ID&lt;/code&gt; and select application type to whatever you want here we will we using &lt;code&gt;Web application&lt;/code&gt;.
Then fill the form, make sure you use &lt;code&gt;port number&lt;/code&gt; which you are using and click on &lt;code&gt;CREATE&lt;/code&gt; and save the &lt;code&gt;client secret and id&lt;/code&gt; .
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_m8M_zqW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7zy2d3h3w8wzco568r4n.jpg" alt="A4" width="880" height="706"&gt;
&lt;/li&gt;
&lt;li&gt;Our GCP preparation are complete lets start or create our application . Lets start with creating react app.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app authloginapp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Most important part of application is adding &lt;code&gt;Google Script&lt;/code&gt;
inside head section of &lt;code&gt;public/index.html&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;&amp;lt;script src="https://accounts.google.com/gsi/client" async defer&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Make sure to add async and defer as they will manage delay.&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now lets change the things to display on screen from &lt;code&gt;src/App.js&lt;/code&gt;.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r0aPT_0p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4d0fhf4fs92cxupbqzte.jpg" alt="v1" width="880" height="419"&gt;
&lt;/li&gt;
&lt;li&gt;We will use react hooks such as &lt;code&gt;useEffect&lt;/code&gt; and &lt;code&gt;useSate&lt;/code&gt; for creating simple login-form. Add following code in App function .&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;useEffect will Provide us with Jwt-token.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add the following hook to enable google in app
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; useEffect(() =&amp;gt; {
    /* global google */
    google.accounts.id.initialize({
      client_id:
        'Your-Google-client-Id',
      callback: handleCallbackResponse,
    });
   google.accounts.id.renderButton(document.getElementById('signInDiv'), {
      theme: 'outline',
      size: 'large',
    });
  }, []);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Here google.accounts.id is because the script provided.&lt;/code&gt;&lt;br&gt;
&lt;code&gt;Google also Provide various different buttons and function.&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now let's define the function &lt;code&gt;handleCallbackResponse&lt;/code&gt; inside App function.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function handleCallbackResponse(response) {
    console.log('Encoded JWT ID token: ' + response.credential);
  } 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Let's check our progress by running
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;code&gt;On inspecting in console we will get our&lt;/code&gt;jwt-token&lt;code&gt;which is provided by google as verification and also holds user details.&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now it's our job to convert and use the token for that we will we required decoder such as jwt-decode.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install jwt-decode
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Later Update handleCallbackResponse with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var userObject = jwt_decode(response.credential);
console.log(userObject);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;We can now see detailed inscription of user.&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now displaying details we first have to store info in something let's use another use hook &lt;code&gt;useState&lt;/code&gt; for storing user. Add useState for use in app function.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [user, setUser] = useState({});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Later update handleCallbackResponse with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setUser(userObject);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Here, we have information of user now we can display on screen by applying following code.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div id="signInDiv"&amp;gt;&amp;lt;/div&amp;gt;
{user &amp;amp;&amp;amp; (
  &amp;lt;div&amp;gt;
    &amp;lt;img src={user.picture}&amp;gt;&amp;lt;/img&amp;gt;
    &amp;lt;h3&amp;gt;{user.name}&amp;lt;/h3&amp;gt;
    &amp;lt;h4&amp;gt;{user.email}&amp;lt;/h4&amp;gt;
  &amp;lt;/div&amp;gt;
)}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Now we can see name, image and email on screen after login.&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lastly give finishing touch by adding one line to hide signin option after signin in handleCallbackResponse function.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementById('signInDiv').hidden = false;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Our Complete &lt;code&gt;src/App.js&lt;/code&gt; looks something like.
&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, { useEffect, useState } from 'react';
import jwt_decode from 'jwt-decode';
import './App.css';

function App() {
  const [user, setUser] = useState({});

  function handleCallbackResponse(response) {
    console.log('Encoded JWT ID token: ' + response.credential);
    var userObject = jwt_decode(response.credential);
    console.log(userObject);
    setUser(userObject);
    document.getElementById('signInDiv').hidden = true;
  }

  function handleSignOut(event) {
    setUser({});
    document.getElementById('signInDiv').hidden = false;
  }

  useEffect(() =&amp;gt; {
    /* global google */
    google.accounts.id.initialize({
      client_id:
        'Your-Google-Client-Id',
      callback: handleCallbackResponse,
    });  google.accounts.id.renderButton(document.getElementById('signInDiv'), {
      theme: 'outline',
      size: 'large',
    });
  }, []);
 return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;div id="signInDiv"&amp;gt;&amp;lt;/div&amp;gt;
      {user &amp;amp;&amp;amp; (
        &amp;lt;div&amp;gt;
          &amp;lt;img src={user.picture}&amp;gt;&amp;lt;/img&amp;gt;
          &amp;lt;h3&amp;gt;{user.name}&amp;lt;/h3&amp;gt;
        &amp;lt;/div&amp;gt;
      )}
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  This is all required for basic Google enabled authentication system all it required 10 mins.
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Note:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;You can use &lt;code&gt;redux&lt;/code&gt; in place of &lt;code&gt;useState&lt;/code&gt; if you are using it in Stack application.&lt;/li&gt;
&lt;li&gt;You can check other button and functions for Google Auth at &lt;a href="https://developers.google.com/identity"&gt;Google Identity&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Check the &lt;a href="https://github.com/201B153/authloginapp"&gt;FULL CODE&lt;/a&gt; at for better picture.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>googlecloud</category>
    </item>
  </channel>
</rss>
