<?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: Shivang Bhandari</title>
    <description>The latest articles on DEV Community by Shivang Bhandari (@shivangbhandari).</description>
    <link>https://dev.to/shivangbhandari</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%2F26480%2Fa6398f4f-3868-4b17-835a-4c935bec77bf.jpeg</url>
      <title>DEV Community: Shivang Bhandari</title>
      <link>https://dev.to/shivangbhandari</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shivangbhandari"/>
    <language>en</language>
    <item>
      <title>How to build Email/Password Signup with Canonic</title>
      <dc:creator>Shivang Bhandari</dc:creator>
      <pubDate>Thu, 16 Jun 2022 06:19:43 +0000</pubDate>
      <link>https://dev.to/canonic/how-to-build-emailpassword-signup-with-canonic-2fb9</link>
      <guid>https://dev.to/canonic/how-to-build-emailpassword-signup-with-canonic-2fb9</guid>
      <description>&lt;p&gt;In Canonic, we now support projects with a username and password authentication system and in this blog, I'll walk you through how to create one such project and the moving parts around it.&lt;/p&gt;

&lt;p&gt;Authentication is identifying a user with the credentials passed to the backend.&lt;/p&gt;

&lt;p&gt;A prevalent method of managing authentication on any product/project is using the username and password system instead of integrations for third-party authentication.&lt;/p&gt;

&lt;p&gt;In &lt;a href="https://canonic.dev/?utm_source=dev.to&amp;amp;utm_medium=organic_article&amp;amp;utm_campaign=june01-15&amp;amp;utm_term=canonic&amp;amp;utm_content=june13"&gt;Canonic&lt;/a&gt;, we now support projects with a username and password authentication system and in this blog, I'll walk you through how to create one such project and the moving parts around it.&lt;/p&gt;

&lt;h1&gt;
  
  
  Starting a new Project
&lt;/h1&gt;

&lt;p&gt;To get started with understanding the workflow of login and signup authentication for your application, let us start a new project to better understand how the entire thing works on canonic.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;When you go to your canonic dashboard, you will see a create project button similar to the one shown in the below screenshot. Let's click on "Create Project" and get to the next steps.&lt;br&gt;
&lt;a href="https://media.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%2Fw08rma4ll4hinx1yzl5p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fw08rma4ll4hinx1yzl5p.png" alt="Create Project"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now, let us select a template for our project, since we want to build a signup and login app, let's select that template and proceed with the next steps.&lt;br&gt;
&lt;a href="https://media.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%2Fd8deo88g95r02vo7a63t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fd8deo88g95r02vo7a63t.png" alt="Project Tempalte selection"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On the second screen of your project setup, you can then select from multiple options which provider you want to select for login. In this, the username/password method is preselected for you, so let's proceed to the next steps.&lt;br&gt;
&lt;a href="https://media.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%2Fx6vvempp5i3vuxlbb31o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fx6vvempp5i3vuxlbb31o.png" alt="Login Provider Selection Screen"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the next step, add your project name and the region where you want to deploy it, and click on the create button to finalize the project setup.&lt;br&gt;
&lt;a href="https://media.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%2Felgkv50nnelum7q5gw31.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Felgkv50nnelum7q5gw31.png" alt="Deployment Settings screen"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When you click on create you will see a progress screen for the deployment of your project.&lt;br&gt;
&lt;a href="https://media.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%2Fk9btojisnbkj630dnest.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fk9btojisnbkj630dnest.png" alt="Deployment progress screen"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, when the project is deployed, you'll see the below popup on your project home and you can open up a code sandbox when you click on the &lt;code&gt;Frontend&lt;/code&gt; Option in this popup.&lt;br&gt;
&lt;a href="https://media.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%2Fex995lmy2zhhzjda9iaa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fex995lmy2zhhzjda9iaa.png" alt="Deployment Success Popup"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fpuec0s0rlrji4z37bfcr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fpuec0s0rlrji4z37bfcr.png" alt="Frontend Codepen"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this playground, you can then play around with a dummy frontend code consuming the project's APIs to help users signup and log in using username and password.&lt;/p&gt;

&lt;p&gt;Once you make a few entries from the code sandbox project, you can then check this data in your CMS for the project as shown below.&lt;/p&gt;

&lt;h1&gt;
  
  
  Exploring the project graph
&lt;/h1&gt;

&lt;p&gt;When we go to the project's graph, we can see that there is a user table already created for us. This is to enable the username password feature for login. When we click on the user table, we see the settings as shown in the screenshot below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2F7jrya0eodhtdl9kirjzr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2F7jrya0eodhtdl9kirjzr.png" alt="User Table Graph"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, in the settings, in generating endpoints section, there are two endpoints that have been marked as true i.e. &lt;code&gt;LOGIN WITH PASSWORD&lt;/code&gt; and &lt;code&gt;SIGNUP WITH PASSWORD&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Understanding the new APIs
&lt;/h1&gt;

&lt;p&gt;As you have already seen above, there are a couple of APIs which are new in the settings section for the user table. The APIs being &lt;code&gt;LOGIN WITH PASSWORD&lt;/code&gt; and &lt;code&gt;SIGNUP WITH PASSWORD&lt;/code&gt; . &lt;/p&gt;

&lt;p&gt;These APIs are what enable user generation and login using a username/password system.&lt;/p&gt;

&lt;p&gt;Let us go through some basic documentation for these APIs to understand their usage better.&lt;/p&gt;

&lt;h2&gt;
  
  
  loginWithPasswordForUser
&lt;/h2&gt;

&lt;p&gt;Login with password for user API as the name suggests carries out the function of logging an existing user in the system. To process the user login, we need a unique identifier (&lt;code&gt;username&lt;/code&gt; in this case) and a password for the account. If the password and username combination matches, then the API returns a JWT token which can be used for future authentication and the users' details.&lt;/p&gt;

&lt;h2&gt;
  
  
  signupWithPasswordForUser
&lt;/h2&gt;

&lt;p&gt;Signup with password for user API as the name suggests helps us make a new user in our project and sign them up for it. To process user signup, usually, a couple of data points are mandatory, and they are a username, (or email) and, password.&lt;/p&gt;

&lt;p&gt;This API takes username and password as request payload and returns a JWT token which can be used for future authentication of the user. We also get the details of the generated user in the API response.&lt;/p&gt;

&lt;p&gt;You can read more about both these APIs in your project's documentation section.&lt;/p&gt;

&lt;h1&gt;
  
  
  Using the JWT token in APIs
&lt;/h1&gt;

&lt;p&gt;We now know that both the loginWithPasswordForUser and signupWithPasswordForUser APIs return a JWT token which as mentioned above can be used for authorization for the user.&lt;/p&gt;

&lt;p&gt;This can be done in a very simple manner&lt;/p&gt;

&lt;p&gt;Let us assume we have a function that acts as a wrapper for a &lt;code&gt;fetch&lt;/code&gt; call and passes on some parameters to it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;makeApiCall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;params&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;params&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;Authorization&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;TOKEN&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this function, as you can see, we pass an &lt;code&gt;Authorization&lt;/code&gt; token, the value being passed to it can be the token that has been returned after a signup/login call to the project's endpoint.&lt;/p&gt;




&lt;p&gt;And That's it for this post! I hope this walkthrough helped you understand the flow of this setup better and if you have any questions please feel free to comment or reach out!&lt;/p&gt;




</description>
      <category>frontend</category>
      <category>api</category>
      <category>lowcode</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Querying data on your Canonic database!</title>
      <dc:creator>Shivang Bhandari</dc:creator>
      <pubDate>Fri, 27 May 2022 19:14:37 +0000</pubDate>
      <link>https://dev.to/shivangbhandari/querying-data-on-your-canonic-database-2b4h</link>
      <guid>https://dev.to/shivangbhandari/querying-data-on-your-canonic-database-2b4h</guid>
      <description>&lt;p&gt;Whenever we want to interact with our database, there needs to be a signal to our backend that we want to make a change, get some data, update an entry, etc. This is where we query our database. A query is a keyword signifying that our backend has been notified we want to perform an action on our data, and the nature of the action is deduced by what query we want to run.&lt;/p&gt;

&lt;p&gt;A database query is &lt;strong&gt;either an action query or a select query.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select Query - To retrieve data from the database.&lt;/li&gt;
&lt;li&gt;Action Query - For insertion, updating, deleting, or other forms of data manipulation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this blog, I will be walking you through how to perform some basic queries on your &lt;a href="https://canonic.dev/?utm_source=canonic_blog&amp;amp;utm_medium=organic_article&amp;amp;utm_campaign=may16-31&amp;amp;utm_term=canonic&amp;amp;utm_content=may24" rel="noopener noreferrer"&gt;canonic&lt;/a&gt; project that has some existing data entries.&lt;/p&gt;

&lt;p&gt;We will cover:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Filtering data&lt;/li&gt;
&lt;li&gt;Searching for an entry or a group of entries&lt;/li&gt;
&lt;li&gt;Sorting query results&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Searching your data
&lt;/h2&gt;

&lt;p&gt;Searching for data is the most executed operation on a database because by the virtue of storing your data in a database, it is a given you would want to search for this data to perform some operations in your application.&lt;/p&gt;

&lt;p&gt;There are majorly two ways to go about searching your data:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Running a search query for a unique data entry&lt;/li&gt;
&lt;li&gt;Running a search query for a group of data (we will talk more about this in filtering your data section)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To search for a unique data entry, Let's consider we have a list of products in our database and we want only to fetch a unique data entry here.&lt;/p&gt;

&lt;p&gt;Let's take a product inventory project to understand this with real code now!&lt;/p&gt;

&lt;p&gt;We have a project which has a few products listed in the products table as you can see below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fh260s0xaagopd226maoa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fh260s0xaagopd226maoa.png" alt="List of products in demo project"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the Left-hand menu inside the graph, you can see there is an endpoints sub-menu that populates the endpoints for this specific table of products.&lt;/p&gt;

&lt;p&gt;Let us now click on the &lt;code&gt;product&lt;/code&gt; endpoint, because that is the general endpoint where you can get a unique data entry. There will be a similar endpoint for your table pre-created by canonic for you!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click the graph node to open up the settings for this endpoint&lt;/li&gt;
&lt;li&gt;Go to the code section and expand it using the bottom left arrow&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fg2agprilnfkuc0glfeyz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fg2agprilnfkuc0glfeyz.png" alt="Finding a unique product in database"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here you will see, that the method has the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getOne&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;_id&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findOne&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;_id&lt;/span&gt; &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;populate&lt;/span&gt;&lt;span class="p"&gt;([]);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, this method will accept a unique ID for a product in our database and if any entry matches the value for the ID we have passed, we will get that data entry in the response.&lt;/p&gt;

&lt;p&gt;Now let us search for &lt;code&gt;Nike Shoes&lt;/code&gt; entry in our database by passing its unique ID as an argument to our function.&lt;/p&gt;

&lt;p&gt;The best part is you do not actually need to run this code on your frontend to see how this will work, just pass this value in the &lt;strong&gt;Input&lt;/strong&gt; section and press the &lt;code&gt;Test code Button&lt;/code&gt; (play icon) in the center to run this code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fgwihvuq165g02dynx591.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fgwihvuq165g02dynx591.png" alt="Finding a unique product in database with product id"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see above, we passed in a unique ID mapped to the key &lt;code&gt;_id&lt;/code&gt; in an object as the input and we got back our results as expected. Voila!&lt;/p&gt;




&lt;h2&gt;
  
  
  Filter your data
&lt;/h2&gt;

&lt;p&gt;Filtering data is one of the most essential use-cases of querying a database for any product. There are a lot of use-cases where we might have to reduce the fetched data based on some filters because that's just an efficient thing to do.&lt;/p&gt;

&lt;p&gt;To fetch only a subset, we will have to figure out which products we need, and to do that we would need to add constraints. If a product matches the constraint only then do we want is a general understanding.&lt;/p&gt;

&lt;p&gt;This is the perfect use for a filter query.&lt;/p&gt;

&lt;p&gt;The key difference here is instead of using a &lt;code&gt;.findOne()&lt;/code&gt; method in our function, we will leverage &lt;code&gt;.find()&lt;/code&gt; method here.&lt;/p&gt;

&lt;p&gt;As mentioned above, we will use the same list of products to understand the filter query.&lt;/p&gt;

&lt;p&gt;Let's say I only want to search for the &lt;code&gt;Nike Shoes&lt;/code&gt; Product because I need that product's data for some operation.&lt;/p&gt;

&lt;p&gt;Let us go to the project's graph now!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Ff44brvxh2n4kv47d2vqs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Ff44brvxh2n4kv47d2vqs.png" alt="Demo Project graph"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On the Left-hand menu inside the graph, you can see there is an endpoints sub-menu that populates the endpoints for this specific table of products.&lt;/p&gt;

&lt;p&gt;Let us now click on the &lt;code&gt;products&lt;/code&gt; endpoint, because that is the general &lt;code&gt;getAll&lt;/code&gt; endpoint where you can add your filters to get specific data instead of all entries. There will be a similar endpoint for your table pre-created by canonic for you!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click the graph node to open up the settings for this endpoint&lt;/li&gt;
&lt;li&gt;Go to the code section and expand it using the bottom left arrow&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You should have a code interface similar to the below screenshot now open!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fwxdkna0qa6vbn3hoh3ve.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fwxdkna0qa6vbn3hoh3ve.png" alt="Filtering entries in your databse"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here you will see that the method has a code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;populate&lt;/span&gt;&lt;span class="p"&gt;([]);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, this method accepts an arg called &lt;code&gt;query&lt;/code&gt; and this is where we pass our filters. We can filter based on a key in the table.&lt;/p&gt;

&lt;p&gt;For e.g. if I want to filter for a product with the name &lt;code&gt;Nike Shoes&lt;/code&gt; I will have to pass a query that helps me achieve this. To get this result, we simply have to pass &lt;code&gt;{"name": "Nike Shoes"}&lt;/code&gt; as our query.&lt;/p&gt;

&lt;p&gt;Similar to the above example, all you have to do to see if your code runs fine is go to the code tab of this graph node and run it there.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Forhlvpxxqm7mw4ncbi30.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Forhlvpxxqm7mw4ncbi30.png" alt="Filtering entries in database with a query"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see we get an output for this product which is something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
  {
    "name": "Nike Shoes",
    "_id": "62750be6d85a0a00096639f1",
    "createdAt": "2022-05-06T11:52:06.085Z",
    "updatedAt": "2022-05-06T11:52:06.085Z",
  }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is one very basic example of how to filter your data based on a field and its value. You can also create complex queries and filter your data as you like! As long as a data entry matches the query, you will get your data.&lt;/p&gt;




&lt;h2&gt;
  
  
  Sort your query results
&lt;/h2&gt;

&lt;p&gt;Sorting your query results is another major use case that we need for day-to-day operations. One of the classic ones is listing out products. Since we are already talking about a product catalog, the use-case where you need to &lt;strong&gt;list products alphabetically&lt;/strong&gt; as a user might want to see them in alphabetical order, be it sorted from &lt;code&gt;A to Z&lt;/code&gt; or &lt;code&gt;Z to A&lt;/code&gt;. This is a common pattern seen on e-commerce websites as well and is the perfect place to add a sort query.&lt;/p&gt;

&lt;p&gt;For this example, we will be using the &lt;code&gt;getAll&lt;/code&gt; API endpoint, similar to what we used in the above section, and making a small modification in the function by chaining a &lt;code&gt;.sort()&lt;/code&gt; method with our &lt;code&gt;.find()&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;To give you a little more context let us dive briefly into how the sort method actually works. It simply accepts an object as an argument where you can mention the field which you want to sort and the accepted values for this key will be &lt;code&gt;-1 or 1&lt;/code&gt; . Mapping the key  &lt;code&gt;1&lt;/code&gt; will sort it in &lt;strong&gt;ascending order&lt;/strong&gt; while mapping it with &lt;code&gt;-1&lt;/code&gt; will sort it in descending order.&lt;/p&gt;

&lt;p&gt;Let's sort the list of products by their names now!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fn3itbf5e0rhfirlvg9no.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fn3itbf5e0rhfirlvg9no.png" alt="Sorting Query results in Canonic"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have simply chained the sort method and as an argument, we have passed the field we want to sort it by and the order we want to sort it in.&lt;/p&gt;

&lt;p&gt;When we run this query we will get the following results:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[
  {
    "name": "Amul Taaza",
    "_id": "62750bddd85a0a00096639ee",
    "createdAt": "2022-05-06T11:51:57.116Z",
    "updatedAt": "2022-05-06T11:51:57.116Z",
  },
  {
    "name": "Chocolate",
    "_id": "62738392c8db87000927fd50",
    "createdAt": "2022-05-05T07:58:10.536Z",
    "updatedAt": "2022-05-06T11:51:47.080Z",
  },
  {
    "name": "Lays",
    "_id": "62750bd7d85a0a00096639eb",
    "createdAt": "2022-05-06T11:51:51.375Z",
    "updatedAt": "2022-05-06T11:51:51.375Z",
  },
  {
    "name": "Nike Shoes",
    "_id": "62750be6d85a0a00096639f1",
    "createdAt": "2022-05-06T11:52:06.085Z",
    "updatedAt": "2022-05-06T11:52:06.085Z",
  }
]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our data is successfully sorted and that's how we do a sort query!&lt;/p&gt;




&lt;p&gt;Thanks for reading! If you find this story helpful, please click the 👏 button and share it to help others find it! Feel free to leave a comment 💬 below.&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>api</category>
      <category>lowcode</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Build Google Login with Canonic</title>
      <dc:creator>Shivang Bhandari</dc:creator>
      <pubDate>Mon, 11 Apr 2022 06:40:40 +0000</pubDate>
      <link>https://dev.to/canonic/build-google-login-with-canonic-5bi9</link>
      <guid>https://dev.to/canonic/build-google-login-with-canonic-5bi9</guid>
      <description>&lt;p&gt;A key aspect of frontend development and products is the authentication and security of users. Adding Login flows to a project is usually the easiest way to get comfortable with authentication.&lt;/p&gt;

&lt;p&gt;Adding &lt;strong&gt;Login&lt;/strong&gt; flows to a project is usually the easiest way to get comfortable with authentication. As developers get started there are a few questions that come to mind:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to handle passwords&lt;/li&gt;
&lt;li&gt;How to handle reset passwords&lt;/li&gt;
&lt;li&gt;How to encrypt and store them&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why use Third-Party Providers?
&lt;/h2&gt;

&lt;p&gt;Third-party sign-on has proven to be a widely adopted and secure alternative to username/password authentication.&lt;/p&gt;

&lt;p&gt;It’s easier to retrospect on the complexities of having an in-house authentication and managing everything. This would mean all the user data including their passwords will have to be stored on internal servers and it needs to be properly salted and hashed. Managing all the complexity and solving a problem that Google, Facebook, etc. have already solved on a mammoth scale is not the most efficient solution for this problem. Third-party sign-on takes care of all of this for us as we are never dealing with the user credentials. This is done for us by the oAuth provider we have integrated.&lt;/p&gt;

&lt;p&gt;While third-party oAuth service sounds great, when implemented it involves a fair amount of code, getting familiar with provider APIs, and integrating multiple login services is still isn't that straightforward.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Then came Canonic!&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Simplified Authentication using Canonic
&lt;/h2&gt;

&lt;p&gt;At Canonic, we help reduce all this complexity by providing a single API endpoint that can be used for multiple providers. The process stays the same on a high level for all the different logins. In this article, we’ll walk you through &lt;strong&gt;integrating Google Login with ReactJS, powered by Canonic.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So let's get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up the backend
&lt;/h2&gt;

&lt;p&gt;To set up the backend for our authentication, first, let’s head over to &lt;a href="https://canonic.dev/?utm_source=dev.to&amp;amp;utm_medium=organic_article&amp;amp;utm_campaign=april1-15&amp;amp;utm_content=april6"&gt;canonic.dev&lt;/a&gt;. After this, you can log in to canonic, or create a new account if you do not already have one! We provide a free plan to enable developers to try out the product.&lt;/p&gt;

&lt;p&gt;After this, we need to set up a new project and we can name it “Test Login App” or anything else that you would want to name it 😄. Select the “Create” option which would mean we need a new DB Instance for this project (provided by canonic).&lt;/p&gt;

&lt;p&gt;Now we need to create a table that will handle the data which will flow in. We enter the name of our table, let’s name this one “Users”. There are 3 types of tables we can create:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;List&lt;/strong&gt; - This means we’ll be storing multiple records in this table.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Standalone&lt;/strong&gt; - means we can store only one record in this table.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Identity&lt;/strong&gt; - creates a &lt;strong&gt;user&lt;/strong&gt; table where we can enable different login providers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qyNe3hpD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t4bzp3mx2per83wh3hhu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qyNe3hpD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t4bzp3mx2per83wh3hhu.png" alt="New Table UI" width="666" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the next step, We’ll select &lt;strong&gt;identity&lt;/strong&gt; as the type. We’re provided with a bunch of predefined system field that covers most of the user information. You can also add more fields to this table as required.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RKKMGt8Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/on7fmlqkpzfox0qeh92y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RKKMGt8Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/on7fmlqkpzfox0qeh92y.png" alt="Editing Users Table" width="600" height="341"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that our table and fields are ready, we need to enable login providers on this table. To open settings, we click on the table and select identity settings from the tabs. You’ll find a list of all the service providers on your left. For our project, we enable Google login.&lt;/p&gt;

&lt;p&gt;There are 3 fields that are needed in this setup:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Redirect URI&lt;/strong&gt; → The URL where users will be redirected after logging in to google. (for our app purposes, &lt;code&gt;http://localhost:3000/&lt;/code&gt; will be our redirect URL)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Client ID&lt;/strong&gt; → Client ID (provided by google)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Secret&lt;/strong&gt; → Secret (provided by google)
Once all the settings are filled, close the panel and hit deploy on the top right corner.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And &lt;strong&gt;VOILA!&lt;/strong&gt; Our APIs are ready for consumption. Now let’s start with the front end. We’ll use react with GraphQL.&lt;/p&gt;

&lt;p&gt;Need Help in getting the client id and secret from google? Read more about it &lt;a href="https://developers.google.com/identity/gsi/web/guides/get-google-api-clientid"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up the Frontend
&lt;/h2&gt;

&lt;p&gt;Here's what the flow will look like on frontend:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt; - Frontend calls Canonic to get the google URL where the user needs to be redirected for sign in.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt; - After logging in, google will redirect back to our app with a code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt; - We send this code back to Canonic to get the authorization token and user data.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To start the react app, we can go with CRA since it's easy to set up the project using it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="n"&gt;npx&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;create-react-app&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;my-test-frontend&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;cd&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;my-app&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;npm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we install GraphQl in our app&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="c"&gt;# You can use either yarn or npm&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;yarn&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;@&lt;/span&gt;&lt;span class="nx"&gt;apollo/client&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;graphql&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After GraphQL is installed, we head over to Canonic, to get our GraphQL connection URL. Go to project documentation via the vertical navigation bar, at the bottom left, click on the button named &lt;code&gt;API Playground&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You'll see the connection URL in the tab. It'll end in &lt;code&gt;/graphql&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xKo7zyvd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r7t5cdqn3d75dc8759w9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xKo7zyvd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r7t5cdqn3d75dc8759w9.png" alt="Canonic Playground" width="600" height="342"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we have our connection URL ready,&lt;/p&gt;

&lt;p&gt;In order to consume our GraphQL APIs, we need to establish a client using Apollo. We open the &lt;code&gt;index.js&lt;/code&gt; file and wrap our App in ApolloProvider and create our client.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ApolloClient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;InMemoryCache&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ApolloProvider&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@apollo/client&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;ApolloClient&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;COPIED-URI-FROM-CANONIC&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;cache&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;InMemoryCache&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;StrictMode&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ApolloProvider&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ApolloProvider&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/React.StrictMode&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;,
&lt;/span&gt;  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will now enable our frontend application to connect with the backend.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now we need a component for logging in. Let's create LoginComponent. On the screen, the user can interact with a CTA that lets them sign in using google. Once the user is logged in, We'll have to fetch our google login redirect URL (the URL we need to redirect users to. when they click on the button).
For that, we need to call &lt;code&gt;getLoginUrlsForUser&lt;/code&gt; query with the following parameters:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;query&lt;/span&gt; &lt;span class="nx"&gt;Login&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;getLoginUrlsForUser&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;GOOGLE&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In order to call our API and get the login URL, we call &lt;code&gt;useQuery&lt;/code&gt; method from &lt;code&gt;apollo/client&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We create &lt;code&gt;login.js&lt;/code&gt; inside the &lt;code&gt;components&lt;/code&gt; directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useQuery&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@apollo/client&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;LOGIN_URLS_QUERY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt;&lt;span class="s2"&gt;`
  query Login {
    getLoginUrlsForUser {
      GOOGLE
    }
  }
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;Login&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;LOGIN_URLS_QUERY&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Loading&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nb"&gt;Error&lt;/span&gt; &lt;span class="p"&gt;:(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;getLoginUrlsForUser&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;GOOGLE&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;LOGIN&lt;/span&gt; &lt;span class="kd"&gt;with&lt;/span&gt; &lt;span class="nx"&gt;Google&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/a&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Login&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So far we have got a working setup for the google redirection URL.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lItR39As--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/quzi554zmx0jee78ppu4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lItR39As--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/quzi554zmx0jee78ppu4.png" alt="Demo Login Page" width="600" height="338"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next Steps:&lt;br&gt;
Now we need to grab the token from the URL when google redirects back to our application. Then we have to send this token to Canonic, call &lt;code&gt;login&lt;/code&gt; API, and get the authorization token along with the user object.&lt;/p&gt;

&lt;p&gt;So we add a few lines of code to &lt;code&gt;App.js&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Remember, we are running the project on &lt;code&gt;http://localhost:3000/&lt;/code&gt; so google will redirect back to this URL - with code in the URL (It'll look something like this &lt;code&gt;http://localhost:3000/?code=.......&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now in our frontend, We want to check if there's a code in the URL when the component mounts (when the web app loads),  so we use &lt;code&gt;useEffect&lt;/code&gt; to check this.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;urlCode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;URLSearchParams&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;search&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;code&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;urlCode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;CALL&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;LOGIN&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;API&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;HERE&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;So we call our login mutation - our mutation would involve two parameters - Code (Google passes it back) and Service (which will be "GOOGLE" in our case).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;mutation&lt;/span&gt; &lt;span class="nx"&gt;Login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;$code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;$service&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;loginForUser&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;$code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;service&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;$service&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;token&lt;/span&gt;
    &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;_id&lt;/span&gt;
      &lt;span class="nx"&gt;createdAt&lt;/span&gt;
      &lt;span class="nx"&gt;updatedAt&lt;/span&gt;
      &lt;span class="nx"&gt;email&lt;/span&gt;
      &lt;span class="nx"&gt;firstName&lt;/span&gt;
      &lt;span class="nx"&gt;lastName&lt;/span&gt;
      &lt;span class="nx"&gt;avatar&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;url&lt;/span&gt;
        &lt;span class="nx"&gt;name&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💡 &lt;strong&gt;NOTE&lt;/strong&gt;: Since this is a write operation, we'll need to generate a secret key for our Canonic APIs with appropriate permissions. Go back to Canonic --- Go to your project --- project settings located in the left vertical menu --- Access Tokens --- Create a new access token. Be sure to select write permission. Read more about it &lt;a href="https://docs.canonic.dev/concepts/projects/permissions?utm_source=dev.to&amp;amp;utm_medium=organic_article&amp;amp;utm_campaign=april1-15&amp;amp;utm_content=april6"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When we combine our mutation and useEffect in &lt;code&gt;App.js&lt;/code&gt; will look something like this. We import Login Component in our App and depending on whether we have a token or not, we show the login component.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useMutation&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@apollo/client&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Login&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./components/Login&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./App.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;LOGIN_MUTATION&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;gql&lt;/span&gt;&lt;span class="s2"&gt;`
  mutation Login($code: String!, $service: String!) {
    loginForUser(code: $code, service: $service) {
      token
      user {
        _id
        createdAt
        updatedAt
        email
        firstName
        lastName
        avatar {
          url
          name
        }
      }
    }
  }
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;loginMutation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;}]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useMutation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;LOGIN_MUTATION&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;urlCode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;URLSearchParams&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;search&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;code&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;urlCode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;loginMutation&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;variables&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;urlCode&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;service&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;GOOGLE&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;loginForUser&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;token&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Login&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hi&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;you&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;re logged in! You&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="nx"&gt;re&lt;/span&gt; &lt;span class="nx"&gt;email&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;loginForUser&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;)}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Stitching all this together will get the App working and it’ll look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cSXiKzHZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tbh9yume09ct1js1ol02.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cSXiKzHZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tbh9yume09ct1js1ol02.png" alt="Login demo app working example" width="600" height="358"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To add more login providers (Github, Facebook), now you simply enable the login provider on Canonic, fill in the required secret, id, and you're good to go!&lt;/p&gt;

&lt;p&gt;We already have the code mentioned in this blog hosted on Github, Feel free to &lt;a href="https://github.com/canonic-dev/canonic-samples#-google-signin-with-react-using-graphql"&gt;clone this project&lt;/a&gt;, add your own project URL and give it a spin!&lt;/p&gt;

</description>
      <category>lowcode</category>
      <category>frontend</category>
      <category>oauth</category>
      <category>google</category>
    </item>
  </channel>
</rss>
