<?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: yasinkuyuk</title>
    <description>The latest articles on DEV Community by yasinkuyuk (@yasinkuyuk).</description>
    <link>https://dev.to/yasinkuyuk</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%2F853166%2F701dbd76-b0ba-457b-9e1b-fea037885a89.jpeg</url>
      <title>DEV Community: yasinkuyuk</title>
      <link>https://dev.to/yasinkuyuk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yasinkuyuk"/>
    <language>en</language>
    <item>
      <title>Quickstart: How to build To-Do App using React &amp; Altogic?</title>
      <dc:creator>yasinkuyuk</dc:creator>
      <pubDate>Thu, 16 Jun 2022 10:44:35 +0000</pubDate>
      <link>https://dev.to/altogic/quickstart-how-to-build-to-do-app-using-react-altogic-4kjd</link>
      <guid>https://dev.to/altogic/quickstart-how-to-build-to-do-app-using-react-altogic-4kjd</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This article will cover how to code simple CRUD operations in a to-do app using &lt;a href="https://reactjs.org/"&gt;React&lt;/a&gt;, and &lt;a href="https://altogic.com/"&gt;Altogic&lt;/a&gt;, a Backend-as-a-Service platform using its client library.&lt;/p&gt;

&lt;p&gt;You can check out the &lt;a href="https://altogic-react-todo-app-quickstart.vercel.app/"&gt;demo.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What are the features of the to-do app?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create a to-do&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Update to-do status&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Delete a to-do&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;List all to-do’s&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;h2&gt;
  
  
  Create App
&lt;/h2&gt;

&lt;p&gt;We can create an app with the &lt;a href="https://designer.altogic.com/"&gt;Altogic Designer&lt;/a&gt; fast. To create an app via the &lt;strong&gt;Designer&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Log in to &lt;strong&gt;Altogic&lt;/strong&gt; with your credentials.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;New app&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the &lt;strong&gt;App Name&lt;/strong&gt; field, enter a name for the app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And click &lt;strong&gt;Next&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--irPbQ5Dn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2384/0%2AX2I--OPprgURevkd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--irPbQ5Dn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2384/0%2AX2I--OPprgURevkd.png" alt="Define App Credentials" width="880" height="879"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Choose &lt;strong&gt;Blank App&lt;/strong&gt; template, and click on &lt;strong&gt;Next&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Create&lt;/strong&gt; on the “&lt;em&gt;Confirm &amp;amp; create”&lt;/em&gt; tab.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--o4Eap83J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2388/0%2AYXXcM04OnLJ-2XvI.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--o4Eap83J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2388/0%2AYXXcM04OnLJ-2XvI.png" alt="Template Apps" width="880" height="877"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, you can customize your subdomain, but not necessarily to do, &lt;strong&gt;Altogic automatically creates one for you,&lt;/strong&gt; your &lt;code&gt;envUrl&lt;/code&gt;. You don’t need to worry if you lost your &lt;code&gt;envUrl&lt;/code&gt;; you can get it from the &lt;strong&gt;Environments&lt;/strong&gt; view of &lt;strong&gt;Designer&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--advQ6u14--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2800/0%2ArEGLYvRP7m2wVMW2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--advQ6u14--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2800/0%2ArEGLYvRP7m2wVMW2.png" alt="Getting the environment URL" width="880" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After creating our app, we need &lt;code&gt;envUrl&lt;/code&gt; and &lt;code&gt;clientKey&lt;/code&gt; to access our app via &lt;strong&gt;Altogic Client Library&lt;/strong&gt; to create a web application.&lt;/p&gt;

&lt;p&gt;To get the &lt;code&gt;clientKey&lt;/code&gt; we need to enter the app which we have created before and;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;App Settings&lt;/strong&gt; at the left-bottom of the Designer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And click on the &lt;strong&gt;Client library keys&lt;/strong&gt; section.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---47SwRNr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2800/0%2AbY1Y-KsMwkVZ8Sbl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---47SwRNr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2800/0%2AbY1Y-KsMwkVZ8Sbl.png" alt="Getting the client key" width="880" height="511"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can create new &lt;code&gt;clientKey&lt;/code&gt; from that page, but thanks to &lt;strong&gt;Altogic&lt;/strong&gt; for creating one &lt;code&gt;clientKey&lt;/code&gt; automatically for us, so let’s copy the existing &lt;code&gt;clientKey&lt;/code&gt; from the list.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create todo model
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;Models&lt;/strong&gt; on the left sidebar.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;New&lt;/strong&gt; on the right of the screen and select &lt;strong&gt;model.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set model name as &lt;strong&gt;todo&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ensure that &lt;strong&gt;Enable timestamps&lt;/strong&gt; are selected to store the creation date of the blog post.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Next.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HLhuK7Iv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2384/0%2ArFbSDC-1W5agsD4n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HLhuK7Iv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2384/0%2ArFbSDC-1W5agsD4n.png" alt="Define model properties" width="880" height="1041"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Altogic&lt;/strong&gt; provides basic &lt;strong&gt;CRUD&lt;/strong&gt; endpoints and services with the related model by default when you create a new model. Since we use &lt;strong&gt;Altogic Client Library,&lt;/strong&gt; we won’t use these endpoints.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ihBlwsUw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2384/0%2A4hZWJQv5N54LcKvE.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ihBlwsUw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2384/0%2A4hZWJQv5N54LcKvE.png" alt="Default endpoints" width="880" height="1041"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We created our first model, ”todo”. We have to define the model properties &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;dateTime&lt;/code&gt; for the due date, and &lt;code&gt;status&lt;/code&gt;. Since we created the &lt;strong&gt;todo **model, we should define the **name&lt;/strong&gt; property as &lt;em&gt;Text,&lt;/em&gt; &lt;code&gt;dateTime&lt;/code&gt; as &lt;em&gt;Date-time,&lt;/em&gt; and the &lt;code&gt;status&lt;/code&gt; as &lt;em&gt;Boolean.&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click on the &lt;strong&gt;todo&lt;/strong&gt; model on the &lt;em&gt;Models&lt;/em&gt; page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;New Field&lt;/strong&gt; on the right-top of the page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;Text Field→ Text.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set model name &lt;strong&gt;name.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ensure that the &lt;strong&gt;Required field&lt;/strong&gt; is selected.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Create.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Xnvy4DYx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2388/0%2ATDN5D8FJ-MXuKRcJ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Xnvy4DYx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2388/0%2ATDN5D8FJ-MXuKRcJ.png" alt="Create text field" width="880" height="1054"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;New Field&lt;/strong&gt; on the right-top of the page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;Boolean.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set model name &lt;strong&gt;status.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ensure that the &lt;strong&gt;Required field&lt;/strong&gt; is selected.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set default value expression &lt;strong&gt;false.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--v96EF_jF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2384/0%2ACyVMfkrfJxAslLWy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--v96EF_jF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2384/0%2ACyVMfkrfJxAslLWy.png" alt="Create boolean field" width="880" height="952"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;New Field&lt;/strong&gt; on the right-top of the page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;Date-time.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set model name &lt;strong&gt;dateTime.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ensure that the &lt;strong&gt;Required field&lt;/strong&gt; is selected.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set default value expression &lt;strong&gt;DATEADD(NOW(),5).&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--c8r_00he--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2388/0%2AB5IanJ2TjmD6FDZn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--c8r_00he--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2388/0%2AB5IanJ2TjmD6FDZn.png" alt="Create date-time field" width="880" height="951"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We completed the database design and the model definition on &lt;strong&gt;Altogic&lt;/strong&gt; without any coding and complex configuration. Let’s move on to the front-end development.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set up the front-end
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Initialize a React app
&lt;/h3&gt;

&lt;p&gt;We can use &lt;code&gt;create-react-app​&lt;/code&gt; command to initialize a React app:&lt;/p&gt;

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

&lt;/div&gt;
&lt;p&gt;Then, install the Altogic package.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd quickstart-todo
npm install altogic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Set up the environment variables
&lt;/h3&gt;

&lt;p&gt;Environment variables are used to secure your secret keys, reuse them in different places and reduce production mistakes. Create a &lt;code&gt;.env&lt;/code&gt; file in the root directory of your application, open the file in your editor and paste the following.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
Replace &lt;code&gt;YOUR-APPLICATION-ENV-URL&lt;/code&gt; and &lt;code&gt;YOUR-APPLICATION-CLIENT-KEY&lt;/code&gt; with the &lt;code&gt;envUrl&lt;/code&gt; and &lt;code&gt;clientKey&lt;/code&gt; values you retrieved while setting up your backend.&lt;/p&gt;

&lt;p&gt;Next, create a file to create the &lt;strong&gt;Altogic Client&lt;/strong&gt; instance.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir helpers
cd helpers
touch altogic.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This creates an &lt;code&gt;altogic.js&lt;/code&gt; file in the &lt;strong&gt;helpers&lt;/strong&gt; directory. Open the file in your editor and paste the following.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
Here, you need to enter the &lt;code&gt;envUrl&lt;/code&gt; and &lt;code&gt;clientKey&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now, install &lt;strong&gt;Tailwind CSS&lt;/strong&gt; and create tailwind.config.js&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ../
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Add the paths to all of your template files in your &lt;code&gt;tailwind.config.js&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
Add the following directives to your &lt;code&gt;index.css&lt;/code&gt; file.&lt;br&gt;&lt;/p&gt;

&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h2&gt;
  
  
  Development
&lt;/h2&gt;

&lt;p&gt;Since Altogic reduces the complexity of the backend development process, we will code our to-do app with just one main component: &lt;code&gt;App.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Feature &amp;amp; Function Matching:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create a to-do → &lt;code&gt;altogic.db.model("todo").create(todoInstance)&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Update status of the to-do → &lt;code&gt;altogic.db.model("todo").object(todoId).update({FIELD_NAME:newValue})&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;List all to-do’s → &lt;code&gt;altogic.db.model("todo").get()&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Delete a to-do → &lt;code&gt;altogic.db.model("todo").object(todoId).delete()&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We’ve covered all &lt;strong&gt;Altogic Client Library Functions&lt;/strong&gt; that we used in our app. Let’s code it together!&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This article covered how to implement simple CRUD operations using &lt;a href="https://reactjs.org"&gt;React&lt;/a&gt; and &lt;a href="https://clientapi.altogic.com/v1.3.1/modules.html"&gt;Altogic Client Library&lt;/a&gt;. Thanks to &lt;a href="https://altogic.com/"&gt;Altogic&lt;/a&gt;, we can build most of the functionality with just a few lines of code.&lt;/p&gt;

&lt;p&gt;You can check out the &lt;a href="https://github.com/altogic/altogic/tree/main/examples/react-quickstart-todo-app"&gt;GitHub repository&lt;/a&gt; for the rest of the code. You can also clone it and build your app on top of it.&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Quickstart: How to build Blog App using Vue &amp; Altogic?</title>
      <dc:creator>yasinkuyuk</dc:creator>
      <pubDate>Fri, 10 Jun 2022 09:21:32 +0000</pubDate>
      <link>https://dev.to/altogic/quickstart-how-to-build-blog-app-using-vue-altogic-1n0j</link>
      <guid>https://dev.to/altogic/quickstart-how-to-build-blog-app-using-vue-altogic-1n0j</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This article will cover building a Quickstart Blog App using &lt;strong&gt;Vue&lt;/strong&gt; and &lt;a href="https://www.altogic.com"&gt;Altogic&lt;/a&gt;, a backend-as-a-service platform using its client library.&lt;/p&gt;

&lt;p&gt;The application will cover the following features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create blog post&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;List all blog posts&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;View single blog post on a separate page&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can reach out the demo &lt;a href="https://altogic-vue-blog-app-quickstart.vercel.app/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Altogic Designer
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Create App
&lt;/h3&gt;

&lt;p&gt;We can create an app with the &lt;a href="https://designer.altogic.com"&gt;Altogic Designer&lt;/a&gt; really fast. To create an app via the &lt;strong&gt;Designer&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Log in to &lt;strong&gt;Altogic&lt;/strong&gt; with your credentials.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;New app&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the &lt;strong&gt;App name&lt;/strong&gt; field, enter a name for the app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And click &lt;strong&gt;Next&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vY2QRndx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2388/1%2AX3eQP3s8yed9nJduwM-O-g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vY2QRndx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2388/1%2AX3eQP3s8yed9nJduwM-O-g.png" alt="Define App Info" width="880" height="886"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Choose &lt;strong&gt;Blank App&lt;/strong&gt; template, and click on &lt;strong&gt;Next&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Create&lt;/strong&gt; on the &lt;em&gt;“Confirm &amp;amp; create”&lt;/em&gt; tab.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zAeiRXva--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2396/1%2AEVW6M4nLhunex1n_3n7vxQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zAeiRXva--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2396/1%2AEVW6M4nLhunex1n_3n7vxQ.png" alt="Choose Template" width="880" height="880"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, you can customize your subdomain, but not necessarily to do, &lt;strong&gt;Altogic automatically creates one for you,&lt;/strong&gt; which will be your &lt;code&gt;envUrl&lt;/code&gt;. You don’t need to worry if you lost your &lt;code&gt;envUrl&lt;/code&gt;; you can get it from the &lt;strong&gt;Environments&lt;/strong&gt; view of &lt;strong&gt;Designer&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TU7YZfgy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5020/1%2AUD9qNTdbnBgiD5ABedSeNQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TU7YZfgy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5020/1%2AUD9qNTdbnBgiD5ABedSeNQ.png" alt="Getting the environment URL" width="880" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After creating our app, we need &lt;code&gt;envUrl&lt;/code&gt; and &lt;code&gt;clientKey&lt;/code&gt; to access our app via Altogic Client Library to create a web application.&lt;/p&gt;

&lt;p&gt;In order to get the &lt;code&gt;clientKey&lt;/code&gt; we need to enter the app which we have created before and;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;App Settings&lt;/strong&gt; at the left-bottom of the designer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And click on &lt;strong&gt;Client library keys&lt;/strong&gt; section.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ni5xMIew--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3840/1%2ALdVvTmqJT44a3mwAbhCRBg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ni5xMIew--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3840/1%2ALdVvTmqJT44a3mwAbhCRBg.png" alt="Getting the Client Library Key" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can create new &lt;code&gt;clientKey&lt;/code&gt; from that page, but thanks to &lt;strong&gt;Altogic&lt;/strong&gt; for creating one &lt;code&gt;clientKey&lt;/code&gt; automatically for us, so let’s copy the existing &lt;code&gt;clientKey&lt;/code&gt; from the list.&lt;/p&gt;

&lt;p&gt;Additionally, since we won’t use any authentication feature, we have to be able to send requests without session. We have to remove the enforcement of the sessions from the client.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click on the related client key.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Untick the &lt;strong&gt;Enforce session&lt;/strong&gt; checkbox&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7R4UWqc5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2348/1%2AEfghkDCvmucTce_sHa1YQw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7R4UWqc5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2348/1%2AEfghkDCvmucTce_sHa1YQw.png" alt="Enforce Ssssion" width="880" height="1097"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Create Blog Model
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;Models&lt;/strong&gt; on the left sidebar.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;New&lt;/strong&gt; on the right of the screen and select &lt;strong&gt;Model.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set model name as &lt;strong&gt;blogs&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ensure that &lt;strong&gt;Enable timestamps&lt;/strong&gt; is selected to store the creation date of the blog post.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Next.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--t57iYNBJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3000/1%2AFZ7Bb2H-Y8Sc_7X4um9zZw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--t57iYNBJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3000/1%2AFZ7Bb2H-Y8Sc_7X4um9zZw.png" alt="Create Model" width="880" height="880"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Altogic&lt;/strong&gt; provides basic &lt;strong&gt;CRUD&lt;/strong&gt; endpoints and services with the related model by default when you create a new model. Since we use &lt;strong&gt;Altogic Client Library,&lt;/strong&gt; we won’t use these endpoints.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8GYhTvB8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2372/1%2Arc06jKidpUMrJ8RTnq1cRQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8GYhTvB8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2372/1%2Arc06jKidpUMrJ8RTnq1cRQ.png" alt="" width="880" height="1045"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We created our first model &lt;strong&gt;”blogs”.&lt;/strong&gt; All we have to do is define model properties title and content. Since we created the &lt;strong&gt;blogs&lt;/strong&gt; model, we should define the &lt;strong&gt;content&lt;/strong&gt; property as &lt;em&gt;rich text&lt;/em&gt; and the &lt;strong&gt;title&lt;/strong&gt; as &lt;em&gt;text.&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click on the &lt;strong&gt;blogs&lt;/strong&gt; model on the &lt;em&gt;Models&lt;/em&gt; page&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;New Field&lt;/strong&gt; on the right-top of the page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;Text Field→ Text.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set model name &lt;strong&gt;title.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ensure that the &lt;strong&gt;Required field&lt;/strong&gt; is selected.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Create.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--B2TmtZxM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2392/1%2A4om6qJJnOBpsmogNSWrP_A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--B2TmtZxM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2392/1%2A4om6qJJnOBpsmogNSWrP_A.png" alt="" width="880" height="1058"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;New Field&lt;/strong&gt; on the right-top of the page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;Text Field→ Rich Text.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set model name &lt;strong&gt;content.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Create&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We completed the database design and the model definition on &lt;strong&gt;Altogic&lt;/strong&gt; without any coding and complex configuration. Let’s move on to the development of the frontend.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frontend Development
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Create Vue App
&lt;/h3&gt;

&lt;p&gt;First we need to create a Vue app. Ensure that &lt;a href="https://cli.vuejs.org/guide/installation.html"&gt;VueCLI&lt;/a&gt; is installed before the installation.&lt;/p&gt;

&lt;p&gt;Open your terminal and paste the following script. The script will create &lt;code&gt;altogic-vue-blog-app-tutorial&lt;/code&gt; Vue app.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vue create altogic-vue-blog-app-tutorial
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;It is time to install the necessary dependencies!&lt;/p&gt;
&lt;h3&gt;
  
  
  Installation of Altogic Client Library
&lt;/h3&gt;

&lt;p&gt;Install the &lt;strong&gt;Altogic Client Library&lt;/strong&gt; to our project by using NPM or Yarn by running the following command:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install altogic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Create a &lt;code&gt;.env&lt;/code&gt; file in the root directory of your application to set environment variables of the app:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch .env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Paste the following script to your &lt;code&gt;.env&lt;/code&gt; file and replace &lt;code&gt;YOUR-APPLICATION-ENV-URL&lt;/code&gt; and &lt;code&gt;YOUR-APPLICATION-CLIENT-KEY&lt;/code&gt; with the &lt;code&gt;envUrl&lt;/code&gt; and &lt;code&gt;clientKey&lt;/code&gt; you copied before, then return to your terminal.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
Next, create a file to use the &lt;strong&gt;Altogic&lt;/strong&gt; services and client.&lt;/p&gt;

&lt;p&gt;Go back to your root directory and follow the commands below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd src
mkdir helpers
cd helpers
touch altogic.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;code&gt;altogic.js&lt;/code&gt; will be created in the &lt;code&gt;/src/helpers&lt;/code&gt; directory. Open the file in your editor and paste the following.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h3&gt;
  
  
  Installation of VueRouter
&lt;/h3&gt;

&lt;p&gt;Since we need different pages for each blog posts and another route for listing all blog posts, we have to implement a route structure to our app. We will use &lt;code&gt;vue-router&lt;/code&gt; in our app.&lt;/p&gt;

&lt;p&gt;Open the root directory in the terminal and run the following script:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install vue-router
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Installation of Tailwind CSS
&lt;/h3&gt;

&lt;p&gt;We will use &lt;strong&gt;Tailwind CSS&lt;/strong&gt; for styling the project. Run the following commands in the root directory.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -D tailwindcss postcss autoprefixer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Below command will create &lt;code&gt;tailwind.config.js&lt;/code&gt; file:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx tailwindcss init -p
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Open the &lt;code&gt;tailwind.config.js&lt;/code&gt; in editor and copy/paste following script to configure template paths:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Create a &lt;code&gt;index.css&lt;/code&gt; file in &lt;code&gt;src&lt;/code&gt; directory and add the following directives:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Open your &lt;code&gt;main.js&lt;/code&gt; file and add the following script to the header of the file:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Components
&lt;/h3&gt;

&lt;p&gt;Before moving on to the development of the components, you can delete the &lt;code&gt;HelloWorld.vue&lt;/code&gt; component under the &lt;code&gt;src&lt;/code&gt; folder came by default.&lt;/p&gt;

&lt;p&gt;We will develop two single components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;BlogList&lt;/code&gt;: List all blog posts and create a blog post&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;SingleBlog&lt;/code&gt;: View single blog post details&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will create &lt;code&gt;BlogList.vue&lt;/code&gt; and &lt;code&gt;SingleBlog.vue&lt;/code&gt; files in the &lt;code&gt;/src/components&lt;/code&gt; directory. Open the root directory in your project and paste the following script line by line.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd src/components
touch SingleBlog.vue BlogList.vue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;BlogList&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We will list all the blog posts in this component. There is a form structure on the top of this component to create a new blog post.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Altogic Client Library&lt;/strong&gt; provides us to create, get, update, delete, list any instance on the database by elementary functions. We will use create and get functions in our app:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;altogic.db.model(&amp;lt;MODEL_NAME&amp;gt;).get()&lt;/code&gt;: Retrieves all instances from the related table&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;altogic.db.model(&amp;lt;MODEL_NAME&amp;gt;).object(&amp;lt;CREATED_INSTANCE&amp;gt;).create()&lt;/code&gt; Creates an instance on the database with the input data&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We call the &lt;code&gt;altogic.db.model("blogs").get()&lt;/code&gt; function inside the &lt;code&gt;mounted()&lt;/code&gt; to fetch the blogs from the database when the component is rendered.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;SingleBlog&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;SingleBlog&lt;/code&gt; component is the component where you can view a blog’s details such as blog content and creation date.&lt;/p&gt;

&lt;p&gt;Each blog post has its own page in the &lt;strong&gt;/blog/:id&lt;/strong&gt; route where id is the blog’s unique ID. We can reach the ID by &lt;code&gt;this.$route.params.id&lt;/code&gt; inside the Vue component.&lt;/p&gt;

&lt;p&gt;We retrieve the blog data with &lt;code&gt;altogic.db.model("blogs").object(id).get()&lt;/code&gt; function in the &lt;code&gt;mounted()&lt;/code&gt; hook.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Router &amp;amp; Routes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now we have to define our routes to our app. Create a &lt;code&gt;router.js&lt;/code&gt; file inside &lt;code&gt;src&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;We will need two different route type in our app:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Listing blog posts view&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Single blog post view&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will specify our routes with related components in &lt;code&gt;router.js&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
Now, it only remains the passing the router object defined in &lt;code&gt;router.js&lt;/code&gt; file to the app object rendered in &lt;code&gt;main.js&lt;/code&gt; file and defining the router views to our App component.

&lt;p&gt;Open your &lt;code&gt;main.js&lt;/code&gt; file and paste the following code snippet:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
Open your &lt;code&gt;App.vue&lt;/code&gt; file and copy &amp;amp; paste the following code snippet:&lt;br&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
Now, you can run your project by typing &lt;code&gt;npm run serve&lt;/code&gt; on the root directory of the project!

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we developed a full-stack &lt;a href="https://vuejs.org/"&gt;Vue&lt;/a&gt; blog app using &lt;strong&gt;Altogic&lt;/strong&gt; and &lt;a href="https://tailwindcss.com/docs/guides/create-react-app"&gt;Tailwind CSS.&lt;/a&gt; Backend development intimidates the frontend developers in the early stages. However, it took only 2 lines of code to build a backend app with the help of &lt;strong&gt;Altogic Client Library.&lt;/strong&gt; You can reach out the source code of this app &lt;a href="https://github.com/altogic/altogic/tree/main/examples/vue-quickstart-blog-app"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Quickstart: How to build Blog App using React &amp; Altogic?</title>
      <dc:creator>yasinkuyuk</dc:creator>
      <pubDate>Thu, 09 Jun 2022 08:37:43 +0000</pubDate>
      <link>https://dev.to/altogic/quickstart-how-to-build-blog-app-using-react-altogic-5aic</link>
      <guid>https://dev.to/altogic/quickstart-how-to-build-blog-app-using-react-altogic-5aic</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This article will cover building a Quickstart Blog App using &lt;strong&gt;React&lt;/strong&gt; and &lt;a href="https://www.altogic.com"&gt;Altogic&lt;/a&gt;, a backend-as-a-service platform using its client library.&lt;/p&gt;

&lt;p&gt;The application will cover the following features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create blog post&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;List all blog posts&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;View single blog post on a separate page&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can reach out the demo &lt;a href="https://altogic-react-blog-app-quickstart.vercel.app/"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  YouTube Development Vide
&lt;/h3&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/HBREz4_RHqs"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Altogic Designer
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Create App
&lt;/h3&gt;

&lt;p&gt;We can create an app with the &lt;a href="https://designer.altogic.com"&gt;Altogic Designer&lt;/a&gt; really fast. To create an app via the &lt;strong&gt;Designer&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Log in to &lt;strong&gt;Altogic&lt;/strong&gt; with your credentials.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;New app&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the &lt;strong&gt;App name&lt;/strong&gt; field, enter a name for the app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And click &lt;strong&gt;Next&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vY2QRndx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2388/1%2AX3eQP3s8yed9nJduwM-O-g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vY2QRndx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2388/1%2AX3eQP3s8yed9nJduwM-O-g.png" alt="Define App Info" width="880" height="886"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Choose &lt;strong&gt;Blank App&lt;/strong&gt; template, and click on &lt;strong&gt;Next&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Create&lt;/strong&gt; on the &lt;em&gt;“Confirm &amp;amp; create”&lt;/em&gt; tab.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zAeiRXva--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2396/1%2AEVW6M4nLhunex1n_3n7vxQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zAeiRXva--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2396/1%2AEVW6M4nLhunex1n_3n7vxQ.png" alt="Choose Template" width="880" height="880"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, you can customize your subdomain, but not necessarily to do, &lt;strong&gt;Altogic automatically creates one for you,&lt;/strong&gt; which will be your &lt;code&gt;envUrl&lt;/code&gt;. You don’t need to worry if you lost your &lt;code&gt;envUrl&lt;/code&gt;; you can get it from the &lt;strong&gt;Environments&lt;/strong&gt; view of &lt;strong&gt;Designer&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TU7YZfgy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5020/1%2AUD9qNTdbnBgiD5ABedSeNQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TU7YZfgy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5020/1%2AUD9qNTdbnBgiD5ABedSeNQ.png" alt="Getting the environment URL" width="880" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After creating our app, we need &lt;code&gt;envUrl&lt;/code&gt; and &lt;code&gt;clientKey&lt;/code&gt; to access our app via Altogic Client Library to create a web application.&lt;/p&gt;

&lt;p&gt;In order to get the &lt;code&gt;clientKey&lt;/code&gt; we need to enter the app which we have created before and;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;App Settings&lt;/strong&gt; at the left-bottom of the designer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And click on &lt;strong&gt;Client library keys&lt;/strong&gt; section.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ni5xMIew--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3840/1%2ALdVvTmqJT44a3mwAbhCRBg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ni5xMIew--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3840/1%2ALdVvTmqJT44a3mwAbhCRBg.png" alt="Getting the Client Library Key" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can create new &lt;code&gt;clientKey&lt;/code&gt; from that page, but thanks to Altogic for creating one &lt;code&gt;clientKey&lt;/code&gt; automatically for us, so let’s copy the existing &lt;code&gt;clientKey&lt;/code&gt; from the list.&lt;/p&gt;

&lt;p&gt;Additionally, since we won’t use any authentication user, we have to be able to send requests without session. We should remove the enforcement of the sessions from the client.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click on the related client key.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Untick the &lt;strong&gt;Enforce session&lt;/strong&gt; checkbox&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7R4UWqc5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2348/1%2AEfghkDCvmucTce_sHa1YQw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7R4UWqc5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2348/1%2AEfghkDCvmucTce_sHa1YQw.png" alt="Enforce Ssssion" width="880" height="1097"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Create Blog Model
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;Models&lt;/strong&gt; on the left sidebar.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;New&lt;/strong&gt; on the right of the screen and select &lt;strong&gt;Model.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set model name as &lt;strong&gt;blogs&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ensure that &lt;strong&gt;Enable timestamps&lt;/strong&gt; is selected to store the creation date of the blog post.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Next.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--t57iYNBJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3000/1%2AFZ7Bb2H-Y8Sc_7X4um9zZw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--t57iYNBJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3000/1%2AFZ7Bb2H-Y8Sc_7X4um9zZw.png" alt="Create Model" width="880" height="880"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Altogic&lt;/strong&gt; provides basic &lt;strong&gt;CRUD&lt;/strong&gt; endpoints and services with the related model by default when you create a new model. Since we use &lt;strong&gt;Altogic Client Library,&lt;/strong&gt; we won’t use these endpoints.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8GYhTvB8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2372/1%2Arc06jKidpUMrJ8RTnq1cRQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8GYhTvB8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2372/1%2Arc06jKidpUMrJ8RTnq1cRQ.png" alt="Default Endpoints" width="880" height="1045"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We created our first model &lt;strong&gt;”blogs".&lt;/strong&gt; All we have to do is define model properties title and content. Since we created the &lt;strong&gt;blogs **model, we should define the **content&lt;/strong&gt; property as &lt;em&gt;rich text&lt;/em&gt; and the &lt;strong&gt;title&lt;/strong&gt; as &lt;em&gt;text.&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click on the &lt;strong&gt;blogs&lt;/strong&gt; model on the &lt;em&gt;Models&lt;/em&gt; page&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;New Field&lt;/strong&gt; on the right-top of the page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;Text Field → Text.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set model name &lt;strong&gt;title.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ensure that the &lt;strong&gt;Required field&lt;/strong&gt; is selected.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Create.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--B2TmtZxM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2392/1%2A4om6qJJnOBpsmogNSWrP_A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--B2TmtZxM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2392/1%2A4om6qJJnOBpsmogNSWrP_A.png" alt="Create Field" width="880" height="1058"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;New Field&lt;/strong&gt; on the right-top of the page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;Text Field → Rich Text.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set model name &lt;strong&gt;content.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Create&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We completed the database design and the model definition on &lt;strong&gt;Altogic&lt;/strong&gt; without any coding and complex configuration. Let’s move on to the development of the frontend.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frontend Development
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Create React App
&lt;/h3&gt;

&lt;p&gt;First we need to create a React app. Open your terminal and paste the following script. The script will create &lt;code&gt;altogic-react-blog-app-tutorial&lt;/code&gt; React app.&lt;/p&gt;

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

&lt;/div&gt;
&lt;p&gt;It is time to install the necessary dependencies!&lt;/p&gt;
&lt;h3&gt;
  
  
  Installation of Altogic Client Library
&lt;/h3&gt;

&lt;p&gt;Install the Altogic client library to our project by using NPM or Yarn by running the following command:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install altogic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Create a .env file in the root directory of your application to set environment variables of the app:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch .env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Paste the following script to your .env file and replace &lt;code&gt;YOUR-APPLICATION-ENV-URL&lt;/code&gt; and &lt;code&gt;YOUR-APPLICATION-CLIENT-KEY&lt;/code&gt; with the &lt;code&gt;envUrl&lt;/code&gt; and &lt;code&gt;clientKey&lt;/code&gt; you copied before, then return to your terminal.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
Next, create a file to handle the &lt;strong&gt;Altogic&lt;/strong&gt; services and client.&lt;/p&gt;

&lt;p&gt;Go back to your root directory and follow the commands below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd src
mkdir helpers
cd helpers
touch altogic.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;code&gt;altogic.js&lt;/code&gt; will be created in the &lt;code&gt;/src/helpers&lt;/code&gt; directory. Open the file in your editor and paste the following.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h3&gt;
  
  
  Installation of React-Router
&lt;/h3&gt;

&lt;p&gt;Since we need different pages for each blog posts and another route for listing all blog posts, we have to implement a route structure for our app. We will use &lt;code&gt;react-router-dom&lt;/code&gt; in our app.&lt;/p&gt;

&lt;p&gt;Open the root directory in the terminal and run the following script:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install react-router-dom@6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Installation of Tailwind CSS
&lt;/h3&gt;

&lt;p&gt;We will use &lt;strong&gt;Tailwind CSS&lt;/strong&gt; for styling the project. Run the following commands in the root directory.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -D tailwindcss postcss autoprefixer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Below command will create &lt;code&gt;tailwind.config.js&lt;/code&gt; file:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx tailwindcss init -p
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Open the &lt;code&gt;tailwind.config.js&lt;/code&gt; in editor and copy/paste the following script to configure template paths:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
Open &lt;code&gt;index.css&lt;/code&gt; file in &lt;code&gt;src&lt;/code&gt; directory and add the following directives:&lt;br&gt;&lt;/p&gt;

&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h3&gt;
  
  
  Components
&lt;/h3&gt;

&lt;p&gt;We will develop two single components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;BlogList&lt;/code&gt;: List all blog posts and create a blog post&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;SingleBlog&lt;/code&gt;: View single blog post details&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will create &lt;code&gt;BlogList.js&lt;/code&gt; and &lt;code&gt;SingleBlog.js&lt;/code&gt; files in the &lt;code&gt;/src/components&lt;/code&gt; directory. Open the root directory in your project and paste the following script line by line.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd src
mkdir components
cd components
touch SingleBlog.js BlogList.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;BlogList&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We will list all the blog posts in this component. There is a form structure on the top of this component to create a new blog post.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Altogic Client Library&lt;/strong&gt; provides us to create, get, update, delete, list any instance on the database by elementary functions. We will use create and get functions in our app:&lt;/p&gt;

&lt;p&gt;*&lt;code&gt;altogic.db.model(&amp;lt;MODEL_NAME&amp;gt;).get()&lt;/code&gt;: Retrieves all instances from the related table&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;altogic.db.model(&amp;lt;MODEL_NAME&amp;gt;).object(&amp;lt;CREATED_INSTANCE&amp;gt;).create()&lt;/code&gt; Creates an instance on the database with the input data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We call the &lt;code&gt;altogic.db.model("blogs").get()&lt;/code&gt; function inside the &lt;code&gt;useEffect()&lt;/code&gt; to fetch the blogs from the database when the component is rendered.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;SingleBlog&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;SingleBlog&lt;/code&gt; component is the component where you can view a single blog’s details such as blog content and creation date.&lt;/p&gt;

&lt;p&gt;Each blog post has its own page in the /blog/:id route where id is the blog’s unique ID. We can reach the ID with the help of the &lt;code&gt;useParams()&lt;/code&gt; hook inside the React component.&lt;/p&gt;

&lt;p&gt;We retrieve the blog data with &lt;code&gt;altogic.db.model("blogs").object(id).get()&lt;/code&gt; function in the useEffect() hook.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
&lt;strong&gt;App&lt;/strong&gt;

&lt;p&gt;Since we use &lt;code&gt;react-router-dom&lt;/code&gt; for routing we have to use the BrowserRouter component in our &lt;code&gt;index.js&lt;/code&gt; file. Open the &lt;code&gt;index.js&lt;/code&gt; and paste the following script:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
Now, it only remains the customize the main &lt;code&gt;App&lt;/code&gt; component. We have to define the routes in the &lt;code&gt;App&lt;/code&gt; component with rendered components and route params. Paste the following code snippet to your &lt;code&gt;App.js&lt;/code&gt; file:&lt;br&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we developed a full-stack &lt;a href="https://reactjs.org/"&gt;React&lt;/a&gt; blog app using &lt;strong&gt;Altogic&lt;/strong&gt; and &lt;a href="https://tailwindcss.com/docs/guides/create-react-app"&gt;Tailwind CSS.&lt;/a&gt; Backend development intimidates the frontend developers in the early stages. However, it took only 2 lines of code to build a backend app with the help of &lt;strong&gt;Altogic Client Library.&lt;/strong&gt; You can reach out the source code of this app &lt;a href="https://github.com/altogic/altogic/tree/main/examples/react-quickstart-blog-app"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
      <category>lowcode</category>
    </item>
    <item>
      <title>How to code a complete task management tool with Next.js and Altogic?</title>
      <dc:creator>yasinkuyuk</dc:creator>
      <pubDate>Tue, 24 May 2022 12:22:01 +0000</pubDate>
      <link>https://dev.to/altogic/how-to-code-a-complete-task-management-tool-with-nextjs-and-altogic-54c2</link>
      <guid>https://dev.to/altogic/how-to-code-a-complete-task-management-tool-with-nextjs-and-altogic-54c2</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This article will cover how to code a &lt;strong&gt;complete task management tool&lt;/strong&gt; using &lt;a href="https://nextjs.org/"&gt;Next.js&lt;/a&gt;, and &lt;a href="https://altogic.com/"&gt;Altogic&lt;/a&gt;, a Backend-as-a-Service platform using its client library.&lt;br&gt;
You can check out the &lt;a href="https://github.com/altogic/altogic/tree/main/examples/nextjs-task-management-app"&gt;source code&lt;/a&gt; and &lt;a href="https://altogic-nextjs-task-management.vercel.app/"&gt;demo app&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  What are the features of the task management tool?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Create projects.&lt;/li&gt;
&lt;li&gt;Create tasks.&lt;/li&gt;
&lt;li&gt;Update tasks.&lt;/li&gt;
&lt;li&gt;Remove tasks.&lt;/li&gt;
&lt;li&gt;Remove projects.&lt;/li&gt;
&lt;li&gt;Get all tasks.&lt;/li&gt;
&lt;li&gt;Get all projects.&lt;/li&gt;
&lt;li&gt;Toggle the done status.&lt;/li&gt;
&lt;li&gt;Compute stats using Altogic.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Youtube Showcase Video
&lt;/h3&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/BsRWLwo0YWk"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Create an app in Altogic
&lt;/h3&gt;

&lt;p&gt;First things first: To use Altogic, we need to create an app in Altogic. We can create an app in &lt;a href="https://designer.altogic.com/"&gt;Designer&lt;/a&gt; easily. All you need to do is enter a name for your app.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9Zd4uOvE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2ALIuN0SVRMmSNOHK-.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9Zd4uOvE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2ALIuN0SVRMmSNOHK-.png" alt="Create App" width="653" height="538"&gt;&lt;/a&gt;&lt;br&gt;
How to create an application in Altogic Designer.&lt;br&gt;
We need envUrl and clientKey to access our environment via Altogic Client Library. envUrl is specific to each environment, and Altogic initially creates one environment for you when you create your app. Here is how to get the envUrl from environment details page.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4c_LoHHh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2800/1%2ABOnJiPbxiDdhw1JHI91t4Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4c_LoHHh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2800/1%2ABOnJiPbxiDdhw1JHI91t4Q.png" alt="Environment variables" width="880" height="480"&gt;&lt;/a&gt;&lt;br&gt;
We can get the clientKey by clicking on the &lt;strong&gt;App Settings&lt;/strong&gt; button in the left-bottom corner of the &lt;strong&gt;Designer&lt;/strong&gt; and clicking on the &lt;strong&gt;Client library keys&lt;/strong&gt; section.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Q-dDEOxb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2A2h39MCMzJIP7b-fm" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Q-dDEOxb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/0%2A2h39MCMzJIP7b-fm" alt="Client Library Keys" width="820" height="300"&gt;&lt;/a&gt;&lt;br&gt;
Here, Altogic already created one for us, but we can create more client library keys and configure the permissions for different keys.&lt;/p&gt;
&lt;h3&gt;
  
  
  Create models in Altogic
&lt;/h3&gt;

&lt;p&gt;Models define the &lt;strong&gt;data structure and data validation rules&lt;/strong&gt; of your applications. A model is composed of &lt;strong&gt;basic&lt;/strong&gt;, &lt;strong&gt;advanced,&lt;/strong&gt; and &lt;strong&gt;sub-model&lt;/strong&gt; &lt;strong&gt;fields&lt;/strong&gt;. As an analogy, you can think of models as tables and fields as columns in relational databases or models as documents and fields as document properties in non-relational databases.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M6lNQqtL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2800/0%2AvzMUDdgKkXhczuEU" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M6lNQqtL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2800/0%2AvzMUDdgKkXhczuEU" alt="Create Models" width="880" height="310"&gt;&lt;/a&gt;&lt;br&gt;
We need to create two models called &lt;strong&gt;todos&lt;/strong&gt; and &lt;strong&gt;projects&lt;/strong&gt; to keep information of them in the database.&lt;br&gt;
To create a model via the Designer, you have two options. You can either create a model from scratch or a sample JSON document. In either case, first, you need to navigate to the &lt;strong&gt;Models view&lt;/strong&gt; in designer and select &lt;strong&gt;+New&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dQosRP61--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5932/1%2A6uVzdc0nJjFItlet0XbGpQ%402x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dQosRP61--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5932/1%2A6uVzdc0nJjFItlet0XbGpQ%402x.png" alt="Model view" width="880" height="368"&gt;&lt;/a&gt;&lt;br&gt;
After, you can pick a &lt;strong&gt;Model&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iYFWeQC0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2372/1%2ARN5fkXbY3vIkCAEcUe_eNA%402x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iYFWeQC0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2372/1%2ARN5fkXbY3vIkCAEcUe_eNA%402x.png" alt="Model Create Complete" width="880" height="1046"&gt;&lt;/a&gt;&lt;br&gt;
Now, you need to add some fields to your model.&lt;br&gt;
To create a field via the Designer, you need to &lt;strong&gt;Navigate to Models&lt;/strong&gt; view and select the model you would like to add the new field. You will be directed to the model details view.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5HMV2nM0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5936/1%2A-Z6egSB_C_ictA8Im2qkPA%402x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5HMV2nM0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5936/1%2A-Z6egSB_C_ictA8Im2qkPA%402x.png" alt="Model Details" width="880" height="648"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the model details view, select &lt;strong&gt;New field.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;From the dropdown menu, select the &lt;strong&gt;Boolean&lt;/strong&gt; that you would like to create.&lt;/li&gt;
&lt;li&gt;In the field name, type the name.&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Create&lt;/strong&gt;
You need to add the following fields:
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--f81Unxk1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/7456/1%2AJOcyvPlEiml6QLaAoczEpQ%402x.png" alt="Todo Model Fields" width="880" height="348"&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;name&lt;/strong&gt;, which is a &lt;strong&gt;Text.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;userId&lt;/strong&gt;, which is an &lt;strong&gt;Object reference&lt;/strong&gt; to the &lt;strong&gt;users&lt;/strong&gt; model.
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WZTFwM1N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2384/1%2AOobyOMF-4nNv9UXzGII0Ug%402x.png" alt="Model" width="880" height="1042"&gt;
After, you can create the &lt;strong&gt;todos&lt;/strong&gt; model in the same way. And add the following fields:&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;title&lt;/strong&gt;, which is a &lt;strong&gt;Text.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;description&lt;/strong&gt;, which is a &lt;strong&gt;Rich Text&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;dueDate&lt;/strong&gt;, which is a &lt;strong&gt;Date-time&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;priority&lt;/strong&gt;, which is a &lt;strong&gt;Option list&lt;/strong&gt; with values “1,2,3”&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;userId&lt;/strong&gt;, which is an &lt;strong&gt;Object reference&lt;/strong&gt; to the &lt;strong&gt;users&lt;/strong&gt; model.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;status&lt;/strong&gt;, which is a &lt;strong&gt;Boolean&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;projectId&lt;/strong&gt;, which is an &lt;strong&gt;Object reference **to the **projects&lt;/strong&gt; model.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;tags&lt;/strong&gt;, which is a &lt;strong&gt;Basic values list&lt;/strong&gt; of type &lt;strong&gt;Text&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Set up the Frontend
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Install the packages
&lt;/h3&gt;

&lt;p&gt;Before you start to use the npx command, make sure you have NodeJS installed in your development environment. Also, installing VSCode and some extensions might be better for faster development.&lt;br&gt;
💡 You can visit &lt;a href="https://nodejs.org/en/download/"&gt;https://nodejs.org/en/download/&lt;/a&gt; to &lt;strong&gt;download&lt;/strong&gt;.&lt;br&gt;
To get started, open the terminal and create a new Next.js project.&lt;br&gt;
npx create-next-app@latest&lt;br&gt;
Next.js will ask you to name the project. Name it whatever you want; I will use “altogic-task-mgmt-app” for this example. Move to the folder just created and &lt;strong&gt;install the Altogic Client Library&lt;/strong&gt;.&lt;br&gt;
cd altogic-task-mgmt-app&lt;br&gt;
npm i altogic&lt;br&gt;
Open the project in VSCode.&lt;br&gt;
Install &lt;strong&gt;tailwind CSS&lt;/strong&gt; and create tailwind.config.js&lt;br&gt;
npm install -D tailwindcss postcss autoprefixer&lt;br&gt;
npx tailwindcss init -p&lt;br&gt;
Add the paths to all of your template files in your tailwind.config.js file.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

Add the following directives to your globals.css file.
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

Install &lt;strong&gt;Font Awesome&lt;/strong&gt; to use the icons.

&lt;p&gt;npm i --save &lt;a href="http://twitter.com/fortawesome/fontawesome-svg-core"&gt;@fortawesome/fontawesome-svg-core&lt;/a&gt;&lt;br&gt;
npm install --save &lt;a href="http://twitter.com/fortawesome/free-solid-svg-icons"&gt;@fortawesome/free-solid-svg-icons&lt;/a&gt;&lt;br&gt;
npm install --save &lt;a href="http://twitter.com/fortawesome/react-fontawesome"&gt;@fortawesome/react-fontawesome&lt;/a&gt;&lt;br&gt;
npm i @fortawesome/free-brands-svg-icons&lt;br&gt;
Install **@headlesui/react **for styling.&lt;br&gt;
npm i @headlessui/react&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Update the next.config.js file to allow the Next.js Image component to load images from Altogic’s storage. “c1-na.altogic.com” value is retrieved from the envUrl which starts with c1-na.altogic.com in my case.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Set up the environment variables
&lt;/h3&gt;

&lt;p&gt;Environment variables are used to &lt;strong&gt;secure&lt;/strong&gt; your secret keys, &lt;strong&gt;reuse&lt;/strong&gt; them in different places and &lt;strong&gt;reduce&lt;/strong&gt; production mistakes. Create a &lt;code&gt;.env.local&lt;/code&gt; file in the root directory of your application, open the file in your editor and paste the following. You can check more about environment variables in Next.js &lt;a href="https://nextjs.org/docs/basic-features/environment-variables"&gt;here&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
Replace YOUR-APPLICATION-ENV-URL and YOUR-APPLICATION-CLIENT-KEY with the envUrl and clientKey values you retrieved while setting up your backend.&lt;br&gt;
Next, create a file to create the &lt;strong&gt;Altogic Client Library&lt;/strong&gt; instance.&lt;br&gt;
    mkdir helpers&lt;br&gt;
    cd helpers&lt;br&gt;
    touch altogic.js&lt;br&gt;
This creates a altogic.js file in the &lt;strong&gt;helpers directory&lt;/strong&gt;. Open the file in your editor and paste the following.&lt;br&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
Here, you need to enter the envUrl and clientKey. Optionally you can paste signInRedirect to redirect your users to the specified sign-in page in some cases. This works in a way that if users try to perform a session-required action while their session has been destroyed, &lt;strong&gt;Altogic&lt;/strong&gt; redirects them to the signInRedirect route.
&lt;h2&gt;
  
  
  Let’s start coding!
&lt;/h2&gt;

&lt;p&gt;Now we can start integrating the backend into the frontend. For this, we will create a context for managing the tasks and projects. Inside the context, there will be following and more functionalities.&lt;/p&gt;
&lt;h3&gt;
  
  
  Create project objects
&lt;/h3&gt;

&lt;p&gt;Our data models are defined as every task has a project. To create a task, first, we need to create a project. Here is the code for that.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Create task objects
&lt;/h3&gt;

&lt;p&gt;Later, we can create a task in the database.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Manage the states
&lt;/h3&gt;

&lt;p&gt;In the first &lt;strong&gt;useEffect&lt;/strong&gt;, we fetch all the projects and tasks from the database. It runs every time when user changes, in other words when they sign in and sign out.&lt;br&gt;
In the second &lt;strong&gt;useEffect&lt;/strong&gt;, we clear the filters we applied before, compute the stats from the database, and set the selectedTodos array accordingly. This runs when currentProject or todos changes.&lt;br&gt;
In the third &lt;strong&gt;useEffect&lt;/strong&gt;, we set the current project when projects change.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Compute stats using Altogic
&lt;/h3&gt;

&lt;p&gt;In apps like task management apps, we need to show some statistics to the user. &lt;strong&gt;Altogic&lt;/strong&gt; makes it much easier to compute complex statistics in the backend. For this we will use &lt;code&gt;altogic.db.model(“todos”).group(“priority”).compute({name:“count”,type:“count”})&lt;/code&gt; function. This function groups the &lt;strong&gt;todos&lt;/strong&gt; objects by priority and counts them by their group and returns the count of each group in a field named “count”.&lt;br&gt;
You can &lt;a href="https://clientapi.altogic.com/v1.3.1/classes/QueryBuilder.html#compute"&gt;check out the documentation&lt;/a&gt; for more information.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Toggle the done status
&lt;/h3&gt;

&lt;p&gt;Now we have created projects and tasks, we should implement a function to update the status of the tasks.&lt;br&gt;
We will use update method of the &lt;strong&gt;ObjectManager&lt;/strong&gt; in Altogic Client Library.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Remove a task
&lt;/h3&gt;

&lt;p&gt;To remove a task, we will use the delete method of the &lt;strong&gt;ObjectManager&lt;/strong&gt; in Altogic Client Library.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Remove a project
&lt;/h3&gt;

&lt;p&gt;When we remove a project, we need to remove all the tasks in it as well.&lt;br&gt;
To remove a task, we will use the delete method of the &lt;strong&gt;ObjectManager&lt;/strong&gt; and the delete method of the &lt;strong&gt;QueryBuilder&lt;/strong&gt; in Altogic Client Library.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Update a task
&lt;/h3&gt;

&lt;p&gt;Users might want to update the title, description, due date, or priority fields of a task.&lt;br&gt;
To update a task, we will use the update method of the &lt;strong&gt;ObjectManager&lt;/strong&gt; in Altogic Client Library.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Get all projects
&lt;/h3&gt;

&lt;p&gt;Get all project objects from the database using the get method of &lt;strong&gt;QueryBuilder&lt;/strong&gt; in Altogic Client Library.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Get all tasks
&lt;/h3&gt;

&lt;p&gt;Get all task objects from the database using the get method of &lt;strong&gt;QueryBuilder&lt;/strong&gt; in Altogic Client Library.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  TaskContext Full Code
&lt;/h3&gt;

&lt;p&gt;In the above, we have connected our frontend application with &lt;strong&gt;Altogic&lt;/strong&gt;. There are more functions for sorting, toggling modals, etc. and you can check them from &lt;a href="https://github.com/altogic/altogic/blob/main/examples/nextjs-task-management-app/context/taskContext.js"&gt;our repository&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This article covered how to implement a task management app using &lt;a href="https://nextjs.org/"&gt;Next.js&lt;/a&gt;, and &lt;a href="https://clientapi.altogic.com/v1.3.1/modules.html"&gt;Altogic Client Library&lt;/a&gt;. Thanks to &lt;a href="https://altogic.com/"&gt;Altogic&lt;/a&gt;, we can build most of the functionality with just a few lines of code.&lt;br&gt;
You can check out the &lt;a href="https://github.com/altogic/altogic/tree/main/examples/nextjs-task-management-app"&gt;GitHub repository&lt;/a&gt; for other functionalities and the rest of the code. You can also clone it and build your app on top of it.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tailwindcss</category>
      <category>webdev</category>
      <category>react</category>
    </item>
    <item>
      <title>How to build OAuth Provider Authentication with React and Altogic</title>
      <dc:creator>yasinkuyuk</dc:creator>
      <pubDate>Thu, 05 May 2022 10:59:59 +0000</pubDate>
      <link>https://dev.to/altogic/how-to-build-oauth-provider-authentication-with-react-and-altogic-1g75</link>
      <guid>https://dev.to/altogic/how-to-build-oauth-provider-authentication-with-react-and-altogic-1g75</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This article will cover OAuth Provider Authentication basics using &lt;strong&gt;React&lt;/strong&gt; and &lt;a href="https://www.altogic.com"&gt;Altogic&lt;/a&gt;, a backend-as-a-service platform using its client library. You can checkout the &lt;a href="https://github.com/altogic/altogic/tree/main/examples/react-oauth-provider-authentication"&gt;Github repository&lt;/a&gt; and the &lt;a href="https://altogic-react-oauth-provider-auth.vercel.app/"&gt;demo application&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So, what is OAuth provider authentication?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The term OAuth stands for Open Authorization with 3rd party application such as social providers. Users can sign in to the application using their &lt;strong&gt;Google, Facebook, Twitter, Discord, Github&lt;/strong&gt; accounts.&lt;/p&gt;

&lt;p&gt;Provider redirects us to the specific route in the application with &lt;em&gt;authorization token&lt;/em&gt;. It is critical to emphasize that the shared content is &lt;em&gt;authorization token&lt;/em&gt;, not your password data.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/tQJoT8bybMU"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  How does the OAuth Provider Authentication work?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Users select the OAuth provider from the frontend application&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After clicking the provider’s button, user is redirected related authorization page of the provider&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Users type their credentials on the providers sign in page&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The provider redirects user to the frontend application’s specific route called as &lt;strong&gt;Development-Callback URL&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The frontend application fetches and handles the response comes from the provider&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Creating App in Altogic
&lt;/h2&gt;

&lt;p&gt;We can create an app with the &lt;a href="https://designer.altogic.com"&gt;Altogic Designer&lt;/a&gt;** really fast. To create an app via the &lt;strong&gt;Designer&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Log in to &lt;strong&gt;Altogic&lt;/strong&gt; with your credentials.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;New app&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the &lt;strong&gt;App name&lt;/strong&gt; field, enter a name for the app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And click &lt;strong&gt;Create&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YWkPubiH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A72gLAS71Uz3LnOsnWTqv_g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YWkPubiH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A72gLAS71Uz3LnOsnWTqv_g.png" alt="Creating App in Altogic" width="653" height="538"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, you can customize your subdomain, but not necessarily to do, &lt;strong&gt;Altogic&lt;/strong&gt; automatically creates one for you, which will be your &lt;code&gt;envUrl&lt;/code&gt;. You don’t need to worry if you lost your &lt;code&gt;envUrl&lt;/code&gt;; you can get it from the &lt;strong&gt;Environments&lt;/strong&gt; view of &lt;strong&gt;Designer&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TU7YZfgy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5020/1%2AUD9qNTdbnBgiD5ABedSeNQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TU7YZfgy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5020/1%2AUD9qNTdbnBgiD5ABedSeNQ.png" alt="Getting the environment URL" width="880" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After creating our app, we need &lt;code&gt;envUrl&lt;/code&gt; and &lt;code&gt;clientKey&lt;/code&gt; to access our app via Altogic Client Library to create a web application.&lt;/p&gt;

&lt;p&gt;In order to get the &lt;code&gt;clientKey&lt;/code&gt; we need to enter the app which we have created before and;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;App Settings&lt;/strong&gt; at the left-bottom of the designer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And click on &lt;strong&gt;Client library keys&lt;/strong&gt; section.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Hv2iYqlM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5020/1%2ASvv6xGw7asGDmuBqSSsQPg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Hv2iYqlM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/5020/1%2ASvv6xGw7asGDmuBqSSsQPg.png" alt="Getting Client Library Key" width="880" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can create new &lt;code&gt;clientKey&lt;/code&gt; from that page, but thanks to Altogic for creating one &lt;code&gt;clientKey&lt;/code&gt; automatically for us, so let’s copy the existing &lt;code&gt;clientKey&lt;/code&gt; from the list.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Setup OAuth Provider Authentication with Altogic ?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Altogic&lt;/strong&gt; currently supports 5 different &lt;strong&gt;OAuth&lt;/strong&gt; providers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://console.developers.google.com/"&gt;Google&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developers.facebook.com/"&gt;Facebook&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://dev.twitter.com/"&gt;Twitter&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://discord.com/developers/docs/topics/oauth2"&gt;Discord&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://docs.github.com/en/developers/apps/building-oauth-apps/creating-an-oauth-app"&gt;Github&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can configure any of these providers and combine them. In this tutorial, we will learn the entire key points to configure the OAuth providers with our app.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Redirect URL&lt;/strong&gt; is the link to which your front-end application is redirected after the user signs in with the provider. Firstly, we will configure our frontend application’s &lt;em&gt;Redirect URL *with **Altogic.&lt;/em&gt;*&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;App Settings&lt;/strong&gt; at the left-bottom of the &lt;strong&gt;Designer&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And click on &lt;strong&gt;Authentication&lt;/strong&gt; section.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Type your &lt;strong&gt;Redirect URL&lt;/strong&gt; to the input field.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xkziN9Dk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/4064/1%2A65w0ycGb82et6UEeKwJuiw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xkziN9Dk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/4064/1%2A65w0ycGb82et6UEeKwJuiw.png" alt="" width="880" height="611"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The remaining part is the configuration of the &lt;strong&gt;oAuth&lt;/strong&gt; providers’ client with our app. We have to create an account with the providers we will use. As we indicate early, Altogic currently supports 5 different oAuth providers such as, &lt;strong&gt;Google&lt;/strong&gt;, &lt;strong&gt;Twitter&lt;/strong&gt;, &lt;strong&gt;Facebook&lt;/strong&gt;, &lt;strong&gt;LinkedIn&lt;/strong&gt;, and &lt;strong&gt;Github&lt;/strong&gt;. We can view their configuration details at the bottom of this page. Before moving on to the self-configuration of each provider, there are 4 core concepts to explain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Client ID:&lt;/strong&gt; The ID of the application on the provider side&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Client Secret:&lt;/strong&gt; The secret client key of the application on the provider side&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Development-Callback URL:&lt;/strong&gt; The Redirect URL that we will pass to the application on the provider side&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Client Sign In URL:&lt;/strong&gt; The URL of the providers sign in page linked with our app. Since we have been using the &lt;strong&gt;Altogic Client Library&lt;/strong&gt;, we won’t need this URL to redirect to the providers sign in page&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We covered the fundamental concepts of the OAuth provider authentication. Let’s move on to the providers’ self configuration on their consoles.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Google&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Sign in to your &lt;strong&gt;Google Developer&lt;/strong&gt; account&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;Create Project&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After creating the project select &lt;strong&gt;OAuth Consent Screen&lt;/strong&gt; on the left sidebar&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select user type as &lt;strong&gt;External&lt;/strong&gt; and click on &lt;strong&gt;Create&lt;/strong&gt; button&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fill in the necessary blanks such as &lt;strong&gt;App Domain, Test Users&lt;/strong&gt; , etc.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--81iJS7FE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/6912/1%2AexMUDKpVDO124QwO8xTzIQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--81iJS7FE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/6912/1%2AexMUDKpVDO124QwO8xTzIQ.png" alt="OAuth Consent Screen" width="880" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;After setting up the OAuth Consent Screen, select **Credentials **on the left sidebar&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;Create Credentials → OAuth Client ID&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select application type as &lt;strong&gt;Web Application&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Paste your &lt;strong&gt;Development-Callback URL&lt;/strong&gt; to the &lt;strong&gt;Authorized Redirect URIs&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Your &lt;strong&gt;Client ID&lt;/strong&gt; and &lt;strong&gt;Client Secret&lt;/strong&gt; will be shown in the pop-up after creating the OAuth Client ID or in the right-top of the Credentials tab&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Paste &lt;strong&gt;Client ID&lt;/strong&gt; and &lt;strong&gt;Client Secret **to the related fields on **Altogic Designer&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vDBaIqXt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2920/1%2AAMlOvewEkgvdv31G4wjsBQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vDBaIqXt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2920/1%2AAMlOvewEkgvdv31G4wjsBQ.png" alt="Google Credential" width="880" height="168"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can watch video tutorial of the Configuration of &lt;strong&gt;Google&lt;/strong&gt; &lt;strong&gt;OAuth&lt;/strong&gt; provider:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/vfVKjtp7o8M"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Facebook&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Sign in to your &lt;strong&gt;Facebook Developers&lt;/strong&gt; account&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;Create App&lt;/strong&gt; on the right-top of the home page&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;Consumer&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Set up &lt;strong&gt;Facebook Login&lt;/strong&gt; to your app&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;App Review → Permission and Features&lt;/strong&gt; on the left sidebar&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Get advanced access&lt;/strong&gt; for the public_profile&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;Facebook Login → Settings&lt;/strong&gt; on the left sidebar&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Paste your &lt;strong&gt;Development-Callback URL **to the **Valid OAuth Redirect URIs&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;Settings → Basic&lt;/strong&gt; on the left sidebar&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Copy&amp;amp;paste the &lt;strong&gt;App ID&lt;/strong&gt; and &lt;strong&gt;App Secret **to the related fields on **Altogic Designer.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RgctYfW8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3200/1%2AYOyj9WU9ONPb14-Ju5LiNQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RgctYfW8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3200/1%2AYOyj9WU9ONPb14-Ju5LiNQ.png" alt="Facebook Credetials" width="880" height="734"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can watch video tutorial of the Configuration of &lt;strong&gt;Facebook&lt;/strong&gt; &lt;strong&gt;OAuth&lt;/strong&gt; provider:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/g84vwxsryZk"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Twitter&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Sign in to your &lt;strong&gt;Twitter Developer Portal&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;Create Project&lt;/strong&gt; in the middle of the home page&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enter the necessary information related(App name, description, etc.)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After creating your project, click &lt;strong&gt;Edit&lt;/strong&gt; button on &lt;strong&gt;Authentication Settings&lt;/strong&gt; tab&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make sure &lt;strong&gt;3-legged OAuth&lt;/strong&gt; and &lt;strong&gt;Request email addresses from users&lt;/strong&gt; is selected&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Paste your &lt;strong&gt;Development-Callback URL&lt;/strong&gt; to the &lt;strong&gt;Callback URLs&lt;/strong&gt; field&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Type your &lt;strong&gt;Website, Terms of Service, Privacy Policy URLs&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Change tab to the &lt;strong&gt;Keys and Tokens **and **Regenerate Keys&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Copy&amp;amp;paste the &lt;strong&gt;API Key&lt;/strong&gt; and &lt;strong&gt;Key Secret&lt;/strong&gt; to the related fields on &lt;strong&gt;Altogic Designer.&lt;/strong&gt; (Consumer key and consumer secret)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RQYETCzo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2196/1%2At0uoI5n6wYlfFITsmduZFw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RQYETCzo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2196/1%2At0uoI5n6wYlfFITsmduZFw.png" alt="Twitter Credentials" width="880" height="912"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can watch video tutorial of the Configuration of &lt;strong&gt;Twitter&lt;/strong&gt; &lt;strong&gt;OAuth&lt;/strong&gt; provider:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/tk1cPCezgRw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Discord&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Sign in to your &lt;strong&gt;Discord Developers&lt;/strong&gt; account&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;New Application&lt;/strong&gt; on the right bottom of the home page&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Give your application a name and click on &lt;strong&gt;Create&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;OAuth2&lt;/strong&gt; on the left sidebar&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;Add Redirect&lt;/strong&gt; button&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Paste your &lt;strong&gt;Development-Callback URL&lt;/strong&gt; in here&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Copy&amp;amp;paste the &lt;strong&gt;Client ID&lt;/strong&gt; and &lt;strong&gt;Client Secret&lt;/strong&gt; to the related fields on &lt;strong&gt;Altogic Designer.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9cBMbSTH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3200/1%2AEGWHiOFEMIK0LXUxRid25A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9cBMbSTH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3200/1%2AEGWHiOFEMIK0LXUxRid25A.png" alt="Discord Credentials" width="880" height="293"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can watch video tutorial of the Configuration of &lt;strong&gt;Discord&lt;/strong&gt; &lt;strong&gt;OAuth&lt;/strong&gt; provider:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/e1nFti5ATLs"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Github&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Sign in to your &lt;strong&gt;Github&lt;/strong&gt; account.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open your profile dropdown on the right-top of the page and click &lt;strong&gt;Settings&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;Developer Settings&lt;/strong&gt; at the bottom of the Settings page&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;OAuth Apps&lt;/strong&gt; and click on &lt;strong&gt;Register a new application&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BSnpK63o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3136/1%2A3VqGCUaX1osjDgk1v3AUDA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BSnpK63o--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3136/1%2A3VqGCUaX1osjDgk1v3AUDA.png" alt="Github Create OAuth App" width="880" height="716"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Homepage URL:&lt;/strong&gt; Our frontend application’s index URL&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Authorization callback URL:&lt;/strong&gt; Auth redirect URL that &lt;strong&gt;Altogic&lt;/strong&gt; creates for us&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After creating our OAuth app on Github, there will be Client ID and Client Secrets presented in the General tab. Copy&amp;amp;paste them to the related fields on &lt;strong&gt;Altogic Designer.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dsULRP9B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3200/1%2A1-zYugmgNEFqfxNLpKlIvA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dsULRP9B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3200/1%2A1-zYugmgNEFqfxNLpKlIvA.png" alt="Github Credentials" width="880" height="419"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can watch video tutorial of the Configuration of &lt;strong&gt;Github&lt;/strong&gt; &lt;strong&gt;OAuth&lt;/strong&gt; provider:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/qKfdaAur18g"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Frontend Development
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;Before installing the application, be sure you have already installed NodeJS in your development environment.&lt;/p&gt;

&lt;p&gt;To install&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 You can visit: &lt;a href="https://nodejs.org/en/download/"&gt;https://nodejs.org/en/download/&lt;/a&gt; to download.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To get started, open the terminal and create a new React project&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// creates a react app with the name of 'altogic-oauth-provider-authentication-tutorial'
npx create-react-app altogic-oauth-provider-authentication-tutorial
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;The above command creates a React project in the altogic-oauth-provider-authentication-tutorialdirectory.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd altogic-oauth-provider-authentication-tutorial
touch .env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Create a &lt;code&gt;.env&lt;/code&gt; file in the root directory of your application, open the file in your editor and paste the following.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
Replace &lt;code&gt;YOUR-APPLICATION-ENV-URL&lt;/code&gt; and &lt;code&gt;YOUR-APPLICATION-CLIENT-KEY&lt;/code&gt; with the &lt;code&gt;envUrl&lt;/code&gt; and &lt;code&gt;clientKey&lt;/code&gt; you copied before, then return to your terminal.&lt;/p&gt;

&lt;p&gt;Install the Altogic client library to our project by using NPM or Yarn by running the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Installation of Altogic Client Library with NPM
npm i altogic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Next, create a file to handle the &lt;strong&gt;Altogic&lt;/strong&gt; services and client.&lt;/p&gt;

&lt;p&gt;Go back to your root directory and follow the commands below:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd src
mkdir helpers
cd helpers
touch altogic.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;code&gt;altogic.js&lt;/code&gt; will be created in the src/helpers directory. Open the file in your editor and paste the following.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
The third parameter of &lt;strong&gt;createClient&lt;/strong&gt; function &lt;code&gt;signInRedirect&lt;/code&gt; handles the redirection to the Sign In page automatically when you have invalid session tokens or signed out. This is a beneficial feature for managing sessions in scenarios when you sign out from your mobile phone.&lt;/p&gt;

&lt;h3&gt;
  
  
  User Interface Components
&lt;/h3&gt;

&lt;p&gt;We will use &lt;strong&gt;Tailwind CSS&lt;/strong&gt; and &lt;strong&gt;Headless UI&lt;/strong&gt; library for styling the project. Run the following commands in the root directory to install the library.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -D tailwindcss postcss autoprefixer
npm install @headlessui/react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Below command will create &lt;code&gt;tailwind.config.js&lt;/code&gt; file:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx tailwindcss init -p
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Open the &lt;code&gt;tailwind.config.js&lt;/code&gt; in editor and copy/paste following script to configure template paths:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
Open index.css file in src directory and add the following directives:&lt;br&gt;&lt;/p&gt;

&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
And we will use Font Awesome Icons in our project. You should install the Font Awesome Library to have well-looking components.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Add SVG Core:&lt;/p&gt;

&lt;p&gt;npm i --save @fortawesome/fontawesome-svg-core&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add Icon Packages:&lt;/p&gt;

&lt;p&gt;npm i --save @fortawesome/free-solid-svg-icons&lt;br&gt;
npm i --save @fortawesome/free-regular-svg-icons&lt;br&gt;
npm i --save @fortawesome/free-brands-svg-icons&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add React Component&lt;/p&gt;

&lt;p&gt;npm i --save @fortawesome/react-fontawesome@latest&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We installed the necessary dependencies to our project for styling. Now, it is time to install react-router for routing our Single Page Application(SPA).&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i react-router-dom
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;We completed the installation part of the project. We will use custom button components to style our application. Open your terminal on your root directory and type following commands one by one:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd src
mkdir components
cd components
mkdir Buttons
cd Buttons
touch PrimaryButton.js SecondaryButton.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Above commands will create &lt;code&gt;PrimaryButton&lt;/code&gt; and &lt;code&gt;SecondaryButton&lt;/code&gt; files under &lt;code&gt;/src/components/Buttons&lt;/code&gt;directory. Now, you can copy&amp;amp;paste the following scripts to the related files:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Building Main Components
&lt;/h3&gt;

&lt;p&gt;The next step is to create the core components that we’ll need for our application,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ProviderSelector&lt;/code&gt; A component that can be used for redirection to the provider both sign in and sign up&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;AuthRedirect&lt;/code&gt; A component that the user is redirected to after the provider’s authorization&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;App&lt;/code&gt; The main application component. It renders all the views with their properties.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Switch to the root directory of your react application and run following commands:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd src
mkdir pages
cd pages
touch AuthRedirect.js ProviderSelector.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This creates a pages directory with the components in the src directory. Your folder structure should look similar to the screenshot:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EhWLvKt7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AxC28rfr8FYMNlsQgOQyrgg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EhWLvKt7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AxC28rfr8FYMNlsQgOQyrgg.png" alt="" width="478" height="1212"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since the user must be redirected to the related providers authorization page, we will develop the &lt;code&gt;ProviderSelector&lt;/code&gt; component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Altogic Client Library&lt;/strong&gt; has just one simple method to handle both sign up and sign in cases to simplify the authentication process. A user instance is created in the database right after the first sign in/up action with the application. Therefore; I don’t have to design multiple use cases as a developer. Thus, we will handle sign in and sign up functionalities within just one component. We will be adding two different routes such as &lt;em&gt;/signin&lt;/em&gt; and &lt;em&gt;/signup&lt;/em&gt;, however same component will be rendered inside them with different texts.&lt;/p&gt;

&lt;p&gt;We will design 5 buttons for each provider: &lt;strong&gt;Google, Facebook, Twitter, Github, Discord.&lt;/strong&gt; When the user clicks the related button, it triggers the &lt;code&gt;signin(provider)&lt;/code&gt; function defined inside the component. We will call &lt;strong&gt;Altogic Client Library&lt;/strong&gt; &lt;code&gt;altogic.auth.signInWithProvider(provider)&lt;/code&gt; method to redirect the user to the related authorization page.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IX-Nh8ZR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2124/1%2A7gc-Tfr2WmURt7ZmKWTC1A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IX-Nh8ZR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2124/1%2A7gc-Tfr2WmURt7ZmKWTC1A.png" alt="" width="880" height="1235"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we early noticed in the article, users will be redirected to the frontend of the application with specific routing. We have to catch the return response of the redirection URL and take necessary actions on the application such as setting &lt;code&gt;isAuth&lt;/code&gt; state in the context.&lt;/p&gt;

&lt;p&gt;Now, we will develop a viewless &lt;code&gt;AuthRedirect&lt;/code&gt; component to handle access_token from the provider and check whether the user is authenticated or somehow not.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
&lt;strong&gt;BONUS: Extra Features/Components&lt;/strong&gt;

&lt;p&gt;To focus on the main purpose of the article, we won’t go over with the development of the below components in this article. However, you can reach the source code of the extra feature components from &lt;a href="https://github.com/altogic/altogic/tree/main/examples/react-oauth-provider-authentication"&gt;Github repository&lt;/a&gt; for full-featured app.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Profile&lt;/code&gt; A component that the users can view, upload and remove their profile pictures&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Sessions&lt;/code&gt; A component that the users can view and sign out from their active sessions. Built with SessionTable and SessionItem sub-components.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Footer&lt;/code&gt; ,&lt;code&gt;Header&lt;/code&gt; ,&lt;code&gt;ProfileDropdown&lt;/code&gt; Navigation bar and footer badge&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;NotFound&lt;/code&gt; A component to catch the routes not presented in application routes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Notification&lt;/code&gt; A component that notifies the user about requests/responses&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;RequiresAuth&lt;/code&gt; A wrapper component that checks whether the user is authenticated before rendering a component; otherwise, it redirects the user to the signup/login page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;RequiresNotAuth&lt;/code&gt; A wrapper component that checks whether the user is not authenticated before rendering a component; otherwise, it redirects the user back to the profile page(for example Sign In page).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ModalContext&lt;/code&gt; , ModalProvider Provides context structure to communicate between components to show notifications to the user&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can see the list of related &lt;strong&gt;Altogic&lt;/strong&gt; functions with above features:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
&lt;strong&gt;Authentication Context&lt;/strong&gt;

&lt;p&gt;Here we came to the one of the core component and structure of app, &lt;code&gt;AuthenticationContext&lt;/code&gt; created using &lt;code&gt;useContext()&lt;/code&gt; hook. Context is used to generate shared data accessible across the component hierarchy without passing props to each component. For example, &lt;code&gt;isAuth&lt;/code&gt; state stores the boolean value of is user authenticated or not. Almost every component must use the isAuth state to handle its internal functionalities. I could pass props to each component like parent to child. However it is not flexible and easy to use. I built an &lt;code&gt;AuthenticationContext&lt;/code&gt; to handle and manage all the data and functionalities related with authentication.&lt;/p&gt;

&lt;p&gt;I defined all my Altogic functions and related states in &lt;code&gt;AuthenticationContext&lt;/code&gt; to distribute it to the child components.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
Finally, we have completed the implementation of the core components of our application. It only remains the development of the App component left. You can reach the source code of the additional side components from the &lt;a href="https://github.com/altogic/altogic/tree/main/examples/react-oauth-provider-authentication"&gt;Github repository.&lt;/a&gt;

&lt;p&gt;We defined the routes in the App component. Routes are protected with &lt;code&gt;RequiresAuth&lt;/code&gt; and &lt;code&gt;RequiresNotAuth&lt;/code&gt; restriction components.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
Open the terminal in the root directory and paste the following command to run your application:


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run start&lt;br&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;In this tutorial, we walked through how to configure OAuth Provider Authentication in &lt;a href="https://reactjs.org/"&gt;React&lt;/a&gt; app using &lt;strong&gt;Altogic&lt;/strong&gt; and &lt;a href="https://tailwindcss.com/docs/guides/create-react-app"&gt;Tailwind CSS.&lt;/a&gt; We all covered detailed configuration of &lt;strong&gt;Google, Facebook, Twitter, Discord&lt;/strong&gt; and &lt;strong&gt;Github&lt;/strong&gt; providers in our &lt;strong&gt;Altogic&lt;/strong&gt; app. If you build your backend application with coding in pure programming languages &amp;amp; frameworks; the configuration process will take your time and effort. However, with the significant help of the **Altogic, **we implement only 10 lines of code snippet inside the &lt;code&gt;ProviderSelector&lt;/code&gt;, &lt;code&gt;AuthRedirect&lt;/code&gt; components.&lt;/p&gt;

&lt;p&gt;Check out the &lt;a href="https://github.com/altogic/altogic/tree/main/examples/react-oauth-provider-authentication"&gt;Github repository&lt;/a&gt; for the source code of the application for further details.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to build Phone Number-Based Authentication with React, Altogic and Twilio</title>
      <dc:creator>yasinkuyuk</dc:creator>
      <pubDate>Thu, 28 Apr 2022 18:50:00 +0000</pubDate>
      <link>https://dev.to/altogic/how-to-build-phone-number-based-authentication-with-react-altogic-and-twilio-26la</link>
      <guid>https://dev.to/altogic/how-to-build-phone-number-based-authentication-with-react-altogic-and-twilio-26la</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This article will cover phone number-based authentication basics using React and &lt;a href="https://www.altogic.com" rel="noopener noreferrer"&gt;Altogic&lt;/a&gt;, a backend-as-a-service platform using it’s client library. You can checkout the &lt;a href="https://github.com/altogic/altogic/tree/main/examples/react-phone-authentication" rel="noopener noreferrer"&gt;Github repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So, what is phone number-based authentication?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Users can sign up for the application by providing their phone number and password only. This authentication method does not require users to specify their email addresses. Thus, users can log in to the application using their phone number and the password they set when signing up.&lt;/p&gt;

&lt;p&gt;With phone number authentication, the application will send an SMS code to the user through &lt;em&gt;Twilio&lt;/em&gt;. After users receive the SMS message from the provider, they can use this code to verify their phone number.&lt;/p&gt;

&lt;p&gt;It is also possible to set up the authentication system through other providers such as &lt;em&gt;MessageBird&lt;/em&gt; and &lt;em&gt;Vonage&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;In the rest of the article, I’ll explain how phone authentication works and set up phone number authentication to a Web application using the &lt;strong&gt;Altogic Client Library&lt;/strong&gt; and React as a frontend.&lt;/p&gt;

&lt;h3&gt;
  
  
  YouTube Promo Video
&lt;/h3&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/J4c4DOr39Qg"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  How does Phone Number Based Authentication work?
&lt;/h2&gt;

&lt;p&gt;Authentication with the Phone Number consists of a few steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Users can enter their phone number and password on the Sign Up page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then the system will send an SMS to the given phone number with &lt;strong&gt;Twilio&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After the user enters the verification code in the SMS, the system completes the phone number verification.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Users will be able to sign in 2 ways:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sign in with credentials: Password and phone number&lt;/li&gt;
&lt;li&gt;Sign in with One-Time Passwords(OTP), where OTP is sent as an SMS message&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;OTP: The automatically generated password authenticates the user for a single session.&lt;/p&gt;

&lt;p&gt;Developers can either configure the validity period of the verification code or the user session duration.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Setup Phone Number Based Authentication with Altogic?
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Creating App in Altogic
&lt;/h2&gt;

&lt;p&gt;To enable phone number authentication, we need to create an app in &lt;strong&gt;Altogic&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;We can create an app with the &lt;a href="https://designer.altogic.com" rel="noopener noreferrer"&gt;Altogic Designer&lt;/a&gt; really fast. To create an app via the Designer:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Log in to &lt;strong&gt;Altogic&lt;/strong&gt; with your credentials.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;New app&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the &lt;strong&gt;App name&lt;/strong&gt; field, enter a name for the app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And click &lt;strong&gt;Create.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&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%2Fq0wtiy0ylq5130d15n0o.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%2Fq0wtiy0ylq5130d15n0o.png" alt="Creating App in Altogic" width="653" height="538"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, you can customize your subdomain, but not necessarily to do, &lt;strong&gt;Altogic automatically creates one for you,&lt;/strong&gt; which will be your &lt;code&gt;envUrl&lt;/code&gt;. You don’t need to worry if you lost your &lt;code&gt;envUrl&lt;/code&gt;; you can get it from the &lt;strong&gt;Environments&lt;/strong&gt; view of &lt;strong&gt;Designer&lt;/strong&gt;.&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%2Fw778gnbgnj4cz3s89c4g.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%2Fw778gnbgnj4cz3s89c4g.png" alt="Getting the environment URL" width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After creating our app, we need &lt;code&gt;envUrl&lt;/code&gt; and &lt;code&gt;clientKey&lt;/code&gt; to access our app via &lt;strong&gt;Altogic Client Library&lt;/strong&gt; to create a web application.&lt;/p&gt;

&lt;p&gt;In order to get the &lt;code&gt;clientKey&lt;/code&gt; we need to enter the app which we have created before and;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;App Settings&lt;/strong&gt; at the left-bottom of the designer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And click on &lt;strong&gt;Client library keys&lt;/strong&gt; section.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&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%2Fmansbqot7jeswpboit0c.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%2Fmansbqot7jeswpboit0c.png" alt="Getting Client Library Key" width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can create new &lt;code&gt;clientKey&lt;/code&gt; from that page, but thanks to &lt;strong&gt;Altogic&lt;/strong&gt; for creating one &lt;code&gt;clientKey&lt;/code&gt; automatically for us, so let’s copy the existing &lt;code&gt;clientKey&lt;/code&gt; from the list.&lt;/p&gt;

&lt;p&gt;Really cool! Now everything is ready at the backend, time to continue &lt;strong&gt;Twilio&lt;/strong&gt; Integration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Twilio Integration
&lt;/h2&gt;

&lt;p&gt;You need to sign up for &lt;strong&gt;Twilio&lt;/strong&gt; with a free/paid trial. You need to get the &lt;strong&gt;Account SID&lt;/strong&gt; and &lt;strong&gt;Auth Token&lt;/strong&gt; for integration with Altogic Client Library.&lt;/p&gt;

&lt;p&gt;If you will use the free trial, you will need to take &lt;em&gt;Twilio&lt;/em&gt; phone number to send SMS messages to the users.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Create an Account in &lt;em&gt;Twilio&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open &lt;strong&gt;Console&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Get a trial phone number&lt;/strong&gt; on the left-top of the Console&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Copy &lt;strong&gt;Account SID&lt;/strong&gt;, &lt;strong&gt;Auth Token&lt;/strong&gt; and &lt;strong&gt;My Twilio phone number&lt;/strong&gt; values to the clipboard&lt;/p&gt;&lt;/li&gt;
&lt;/ol&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%2Foe3azxnb6oc81yv9w3pk.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%2Foe3azxnb6oc81yv9w3pk.png" alt="Twilio Credentials" width="800" height="483"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we’ve copied the configuration credentials to the clipboard. In trial accounts, you have to specify the verified phone numbers, which we defined as &lt;em&gt;“to number”&lt;/em&gt; in &lt;strong&gt;Altogic&lt;/strong&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Click on the &lt;strong&gt;Explore Products&lt;/strong&gt; in the left sidebar&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Be sure that **Messaging **and **Phone Numbers **products are selected.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt;Now you can navigate to the &lt;strong&gt;Verified Caller IDs&lt;/strong&gt; page by &lt;strong&gt;Sidebar → Phone Numbers → Manage → Verified Caller IDs.&lt;/strong&gt;&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%2Frprl0big7lzfqw7ruknr.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%2Frprl0big7lzfqw7ruknr.png" width="604" height="704"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should add your phone number as a Verified Caller from here.&lt;/p&gt;

&lt;p&gt;And finally, you have to give geo permission to your phone numbers region. You can go to this page by &lt;strong&gt;Sidebar&lt;/strong&gt; → &lt;strong&gt;Messaging&lt;/strong&gt; → &lt;strong&gt;Settings&lt;/strong&gt; → &lt;strong&gt;Geo permissions.&lt;/strong&gt;&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%2F4q0ion5o5rhw6qva8rrq.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%2F4q0ion5o5rhw6qva8rrq.png" width="705" height="720"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 After configuring the &lt;strong&gt;Twilio&lt;/strong&gt; account, you have to enable the phone number and password based sign up from &lt;strong&gt;Designer → App Settings → Authentication → Mobile Phone Authentication → Enable phone number and password based sign up in Altogic client library.&lt;/strong&gt;&lt;br&gt;
 Paste the &lt;strong&gt;Twilio Account SID&lt;/strong&gt;,&lt;strong&gt;Twilio Authentication Token&lt;/strong&gt; and &lt;strong&gt;Twilio Phone Number&lt;/strong&gt; to the related fields.&lt;/p&gt;
&lt;/blockquote&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%2Fhyc6zr6rrvngjz7zxfov.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%2Fhyc6zr6rrvngjz7zxfov.png" alt="Setting up Twilio with Altogic" width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Frontend Development
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;Before installing the application, be sure you have already installed &lt;code&gt;NodeJS&lt;/code&gt; in your development environment.&lt;/p&gt;

&lt;p&gt;To install&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 You can visit: &lt;a href="https://nodejs.org/en/download/" rel="noopener noreferrer"&gt;https://nodejs.org/en/download/&lt;/a&gt; to download.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To get started, open the terminal and create a new React project&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// creates a react app with the name of `altogic-react-phone-authentication-tutorial`
npx create-react-app altogic-react-phone-authentication-tutorial
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;The above command creates a React project in the &lt;code&gt;altogic-react-phone-authentication-tutorialdirectory&lt;/code&gt;.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd altogic-react-phone-authentication-tutorial
touch .env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Create a &lt;code&gt;.env&lt;/code&gt; file in the root directory of your application, open the file in your editor and paste the following.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
Replace &lt;code&gt;YOUR-APPLICATION-ENV-URL&lt;/code&gt; and &lt;code&gt;YOUR-APPLICATION-CLIENT-KEY&lt;/code&gt; with the &lt;code&gt;envUrl&lt;/code&gt; and &lt;code&gt;clientKey&lt;/code&gt; you copied before, then return to your terminal.&lt;/p&gt;

&lt;p&gt;Install the &lt;strong&gt;Altogic Client Library&lt;/strong&gt; to our project by using NPM or Yarn by running the following command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Installation of Altogic Client Library with NPM
npm i altogic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Next, create a file to handle the &lt;strong&gt;Altogic&lt;/strong&gt; services and client.&lt;/p&gt;

&lt;p&gt;Go back to your root directory and follow the commands below:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd src
mkdir helpers
cd helpers
touch altogic.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;code&gt;altogic.js&lt;/code&gt; will be created in the &lt;code&gt;src/helpers&lt;/code&gt; directory. Open the file in your editor and paste the following.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
The third parameter of &lt;strong&gt;createClient&lt;/strong&gt; function &lt;code&gt;signInRedirect&lt;/code&gt; handles the redirection to the Sign In page automatically when you have invalid session tokens or signed out. This is a beneficial feature for managing sessions in scenarios when you sign out from your mobile phone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building Main React Components
&lt;/h2&gt;

&lt;p&gt;The next step is to create the components that we’ll need for our application,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;SignIn&lt;/code&gt; — A form component that allows the user to sign in.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;SignUp&lt;/code&gt; — A form component that allows the user to sign up.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Verification&lt;/code&gt; — A form component that verifies phone number.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Home&lt;/code&gt; — A component that displays whether or not authentication was successful.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;RequiresAuth&lt;/code&gt; A wrapper component that checks whether the user is authenticated before rendering a component; otherwise, it redirects the user to the signup/login page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;RequiresNotAuth&lt;/code&gt; — A wrapper component that checks whether the user is not authenticated before rendering a component; otherwise, it redirects the user back to the profile page(for example Sign In page).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;App&lt;/code&gt; — The main application component. It renders all the views with their properties.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Sessions&lt;/code&gt; — A table component that allows user to manage and view their sessions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Profile&lt;/code&gt; — A component that users can view and manage profile data.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;switch to the root directory of your react application and run following commands:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd src
mkdir pages
cd pages
touch SignIn.js SignUp.js Verification.js Home.js Sessions.js Profile.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Going back to src directory again, and creating ‘components’ directory. We will create ‘Routes’ directory under ‘components’ directory:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ..
mkdir components
cd components
mkdir Routes
cd Routes
touch RequiresAuth.js RequiresNotAuth.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This creates a pages directory with the components in the &lt;code&gt;src&lt;/code&gt; directory. Your folder structure should look similar to the screenshot&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%2F1i5z0a50zrytvjqihddm.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%2F1i5z0a50zrytvjqihddm.png" width="704" height="1250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We’ll be using React Context API to manage the user and session data, and pass them to the components rendered based on whether the user is authenticated or not. We’ll also be using &lt;a href="https://reacttraining.com/react-router/web/guides/quick-start" rel="noopener noreferrer"&gt;React Router&lt;/a&gt; to handle routing.&lt;/p&gt;

&lt;p&gt;Go back to your root directory and open the terminal:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd src
mkdir context
cd context
touch AuthenticationContext.js ModalContext.js CounterContext.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;To install React Router run the following command.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install react-router-dom
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;We will use &lt;strong&gt;Tailwind CSS&lt;/strong&gt; and &lt;strong&gt;Headless UI&lt;/strong&gt; library for styling the project. Run the following commands in the root directory to install the library.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -D tailwindcss postcss autoprefixer
npm install @headlessui/react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Below command will create tailwind.config.js file:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx tailwindcss init -p
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Open the tailwind.config.js in editor and copy/paste following script to configure template paths:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
Open index.css file in src directory and add the following directives:&lt;br&gt;&lt;/p&gt;

&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
And we will use Font Awesome Icons in our project. You should install the Font Awesome Library to have well-looking components.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add SVG Core:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    npm i &lt;span class="nt"&gt;--save&lt;/span&gt; @fortawesome/fontawesome-svg-core
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Add Icon Packages:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    npm i --save @fortawesome/free-solid-svg-icons
    npm i --save @fortawesome/free-regular-svg-icons
    npm i --save @fortawesome/free-brands-svg-icons
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Add React Component
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    npm i --save @fortawesome/react-fontawesome@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Since we built a phone number-based authentication app, we will need a phone number input field. We will use &lt;a href="https://www.npmjs.com/package/react-phone-number-input" rel="noopener noreferrer"&gt;react-phone-number-input &lt;/a&gt;library to increase UX.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i react-phone-number-input
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Finally all dependencies have been installed on our local machine. We can start our application by typing npm run start on the root directory. Let’s start coding!&lt;/p&gt;
&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;First of all, we will need some interface views and components such as;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Verification&lt;/code&gt; Phone number verification page&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ResetPassword&lt;/code&gt; and &lt;code&gt;ResetPasswordCode&lt;/code&gt; Sends users an SMS to reset their password&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;NotVerified&lt;/code&gt; Informs users that their phone number is not verified yet, and resends verification code&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Counter&lt;/code&gt; Simple countdown timer for verification codes validity&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Footer&lt;/code&gt;, &lt;code&gt;Header&lt;/code&gt;, &lt;code&gt;ProfileDropdown&lt;/code&gt; Navigation bar and footer badge&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Notification&lt;/code&gt; Informs users about the responses&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;SessionTable&lt;/code&gt; and &lt;code&gt;SessionItem&lt;/code&gt; for listing sessions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ChangeCredentials&lt;/code&gt; Tab structure to change view for &lt;code&gt;ChangePhone&lt;/code&gt; and &lt;code&gt;ChangePassword&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;PrimaryButton&lt;/code&gt; and &lt;code&gt;SecondaryButton&lt;/code&gt; Custom buttons&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Open your root directory and copy&amp;amp;paste lines one by one to create files.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd src/components
touch Counter.js Footer.js Header.js Notification.js ProfileDropdown.js SessionItem.js SessionTable.js

mkdir Buttons
mkdir Profile

cd Buttons
touch PrimaryButton.js SecondaryButton.js

cd ../Profile
touch ChangeCredentials.js ChangePhone.js ChangePassword.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;We will need two parent components that instruct routing rules to their child component. Rules mean,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Authenticated users are not able to view Sign Up and Sign In pages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Unauthenticated users are not able to view Profile and Sessions pages.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since we have restricted rules, We have designed special particular components that restrict the child components: RequiresNotAuth and RequiresAuth&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
RequiresNotAuth.js&lt;br&gt;&lt;/p&gt;

&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
App.js This will be main component of our application. All routes and views will be rendered in App component.&lt;br&gt;&lt;/p&gt;

&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
As you can see in the App.js component, we have three different Provider&amp;amp;Context structure:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;AuthenticationProvider:&lt;/strong&gt; Stores functions, states that are related with authentication, such as calling &lt;strong&gt;Altogic Client Library&lt;/strong&gt; functions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;ModalProvider:&lt;/strong&gt; Manages push notification flow in the app&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;CounterProvider:&lt;/strong&gt; Stores and handles the deadline of the verification code’s expiry date&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Just for now, I am skipping the implementation of AuthenticationContext, we will have further been discussing “How to build context provider structure and how it works?”.&lt;/p&gt;

&lt;p&gt;Since we built a phone number based authentication app; we need &lt;code&gt;SignIn&lt;/code&gt; and &lt;code&gt;SignUp&lt;/code&gt; components to handle form actions. I’ve excluded all the functions ,which works asynchronously because of the &lt;strong&gt;Altogic&lt;/strong&gt; connections, to the Authentication Context to manage and access it easily from other components.&lt;/p&gt;

&lt;p&gt;Let’s start coding the &lt;code&gt;SignUp&lt;/code&gt; component first. We have a form structure to receive necessary data from the user. There is a button to handle the registration process at the bottom of the form structure. When you click this button, the &lt;code&gt;signup()&lt;/code&gt; function is triggered, defined in the 23rd line. Here, we call &lt;code&gt;context.signup()&lt;/code&gt; function defined in AuthenticationContext. Thus, &lt;strong&gt;Altogic&lt;/strong&gt; functions stay together and stored in the context.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&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%2F4uyaimfk9gywztzwuy6v.png" alt="Sign Up page preview" width="800" height="532"&gt;

&lt;p&gt;We’ve entirely coded the sign up form. Now, we need a sign in form to sign users in.&lt;/p&gt;

&lt;p&gt;We’ve developed &lt;code&gt;signin()&lt;/code&gt; function -in line 24-, that will be triggered after the user clicks the button. Like with the &lt;code&gt;SignUp&lt;/code&gt; component, &lt;code&gt;context.signin()&lt;/code&gt; will be triggered inside the component’s own function.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&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%2Fka2zvfurd5ysv3o0ocwv.png" alt="Sign In page review" width="800" height="527"&gt;

&lt;p&gt;We have finished the implementation of the Sign Up and Sign In page. Since the users have to verify their phone number, we need to built a &lt;code&gt;Verification&lt;/code&gt; component, which will take verification code as single parameter. When you click to the button, &lt;code&gt;verify()&lt;/code&gt; defined inside the function, will be executed. In this function, we execute &lt;code&gt;context.verifyPhoneNumber()&lt;/code&gt; function to verify our phone number with &lt;strong&gt;Altogic.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&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%2F9crekfdw7icuz7faya1i.png" alt="Verify Phone Number page preview" width="800" height="531"&gt;

&lt;p&gt;The common point of the three component &lt;code&gt;SignIn&lt;/code&gt;, &lt;code&gt;SignUp&lt;/code&gt; and &lt;code&gt;Verification&lt;/code&gt; is; they three have buttons, functions and forms inside the component. Also, they also importing &lt;code&gt;AuthenticationContext&lt;/code&gt; as context. I want to explain the simplified workflow of communications between components and contexts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;User clicks the button Sign In, Sign Up, Verify&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Clicking triggers &lt;code&gt;signin()&lt;/code&gt;, &lt;code&gt;signup()&lt;/code&gt;, &lt;code&gt;verify()&lt;/code&gt; function inside component&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;context.signIn()&lt;/code&gt; function is called by &lt;code&gt;handleClick()&lt;/code&gt;function&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Authentication Context&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Finally, we came to the Context API part. Before moving on to the coding section, I think going over the &lt;strong&gt;Altogic Client Library&lt;/strong&gt; functions will be very helpful.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;altogic&lt;/strong&gt;.auth.signUpWithPhone(phoneNumber, password, name) → Takes 3 parameters (Name field is optional)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;altogic&lt;/strong&gt;.auth.signInWithPhone(phoneNumber, password) → Return user and session response if the credentials are correct&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;altogic&lt;/strong&gt;.auth.signOut(token) → Kill the given token and sign out from the related session&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;altogic&lt;/strong&gt;.auth.signOutAll() → Sign out from all session related with your account&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;altogic&lt;/strong&gt;.auth.resendVerificationCode(phoneNumber) → Resend verification code to verify your phone number&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;altogic&lt;/strong&gt;.auth.changePassword(newPassword, oldPassword) → Change password&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;altogic&lt;/strong&gt;.auth.getAllSessions() → Get list of all active sessions with your account&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;altogic&lt;/strong&gt;.auth.sendResetPwdCode(phoneNumber) → Send a verification code to your phone number if you forgot your password&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;altogic&lt;/strong&gt;.auth.resetPwdWithCode(phoneNumber,code,password) → Reset your password&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;altogic&lt;/strong&gt;.auth.changePhone(password, phoneNumber) → Change phone number function takes phone number and password as arguement&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;altogic&lt;/strong&gt;.auth.verifyPhone(phoneNumber, code) → Verify phone number with your verification code that comes to your phone number&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here we came to the one of the core component and structure of app, &lt;code&gt;AuthenticationContext&lt;/code&gt; created using &lt;code&gt;useContext()&lt;/code&gt; hook. Context is used to generate shared data accessible across the component hierarchy without passing props to each component. For example, &lt;code&gt;isAuth&lt;/code&gt; state stores the boolean value of is user authenticated or not. Almost every component must use the &lt;code&gt;isAuth&lt;/code&gt; state to handle it’s internal functionalities. I could pass props to each component like parent to child. However it is not flexible and easy to use. I built an &lt;code&gt;AuthenticationContext&lt;/code&gt; to handle and manage all the data and functionalities related with authentication.&lt;/p&gt;

&lt;p&gt;I defined all my &lt;strong&gt;Altogic&lt;/strong&gt; functions and related states in &lt;code&gt;AuthenticationContext&lt;/code&gt; to distribute it to the child components.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
&lt;strong&gt;BONUS: EXTRA FEATURES&lt;/strong&gt;

&lt;p&gt;You can find extra features in the shared repository. Also you can find more and more functions, database queries, etc. In fact all your needs to build a backend app.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Upload profile photo&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Remove profile photo&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Update credentials(phone number and password)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;List all sessions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sign out from other sessions&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sign out from all sessions&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can see the list of related &lt;strong&gt;Altogic&lt;/strong&gt; functions with above features:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
&lt;strong&gt;Conclusion&lt;/strong&gt;

&lt;p&gt;In this tutorial, we walked through how to secure and verify your users in a &lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;React&lt;/a&gt; app using &lt;strong&gt;Altogic,&lt;/strong&gt; &lt;a href="https://www.twilio.com/" rel="noopener noreferrer"&gt;Twilio&lt;/a&gt; and &lt;a href="https://tailwindcss.com/docs/guides/create-react-app" rel="noopener noreferrer"&gt;Tailwind CSS.&lt;/a&gt; Phone number-based authentication is one of the standard authentication method in the sector. Additionally, as a full-stack developer, I have to say that building the backend of the phone number-based authentication apps becomes so confusing to handle with coding the backend and integrating the 3rd party SMS providers simultaneously. &lt;strong&gt;Altogic&lt;/strong&gt; provides terrific services and functions to create a backend app for phone number authentication. As we experienced in the article, it took just a few lines of code to build a backend app.&lt;/p&gt;

&lt;p&gt;This super powerful and easy-to-implement app should be a baseline for your phone number-based projects, and you would develop on it. You should &lt;a href="https://github.com/altogic/altogic/tree/main/examples/react-phone-authentication" rel="noopener noreferrer"&gt;check out the repository&lt;/a&gt; for the application we built on GitHub for further details.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>authentication</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
