<?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: Altogic</title>
    <description>The latest articles on DEV Community by Altogic (@altogic).</description>
    <link>https://dev.to/altogic</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%2Forganization%2Fprofile_image%2F5556%2F686ca1c3-edc9-4dfe-8112-57fc7c325868.png</url>
      <title>DEV Community: Altogic</title>
      <link>https://dev.to/altogic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/altogic"/>
    <language>en</language>
    <item>
      <title>Introducing Serverless Functions</title>
      <dc:creator>Deniz</dc:creator>
      <pubDate>Mon, 31 Oct 2022 12:12:33 +0000</pubDate>
      <link>https://dev.to/altogic/introducing-serverless-functions-4ln5</link>
      <guid>https://dev.to/altogic/introducing-serverless-functions-4ln5</guid>
      <description>&lt;p&gt;We are excited to announce the release of serverless functions. 🚀🔥 &lt;/p&gt;

&lt;p&gt;With serverless (full-code) functions, you can write simple, single-purpose functions (e.g., custom code) that are attached to events emitted from your Altogic backend application.&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
      &lt;div class="c-embed__cover"&gt;
        &lt;a href="https://www.altogic.com/blog/introducing-serverless-full-code-functions/" class="c-link s:max-w-50 align-middle" rel="noopener noreferrer"&gt;
          &lt;img alt="" src="https://res.cloudinary.com/practicaldev/image/fetch/s--lol_gdJh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.altogic.com/blog/img/blog/2022-10-31/serverless-functions.png" height="468" class="m-0" width="650"&gt;
        &lt;/a&gt;
      &lt;/div&gt;
    &lt;div class="c-embed__body"&gt;
      &lt;h2 class="fs-xl lh-tight"&gt;
        &lt;a href="https://www.altogic.com/blog/introducing-serverless-full-code-functions/" rel="noopener noreferrer" class="c-link"&gt;
          Introducing serverless (full-code) functions | Altogic - Backend as a service platform
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;p class="truncate-at-3"&gt;
          We are excited to announce the release of serverless (full-code) functions. With full-code functions, you write simple, single-purpose functions (e.g., custom code) that are attached to events emitted from your backend application.
        &lt;/p&gt;
      &lt;div class="color-secondary fs-s flex items-center"&gt;
          &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://res.cloudinary.com/practicaldev/image/fetch/s--g1I8BQUT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.altogic.com/blog/img/favicon.ico" width="256" height="256"&gt;
        altogic.com
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Now, you can create both no-code services or full-code functions to handle the backend needs of your apps.&lt;/p&gt;

&lt;p&gt;We provide the best of both worlds, the speed to develop functions with no-code, and the flexibility to handle complex requirements with full-code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BVrJdcaF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.circle.so/yozuebq0h86b93leu1gttz5j862h" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BVrJdcaF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.circle.so/yozuebq0h86b93leu1gttz5j862h" alt="https://cdn.circle.so/yozuebq0h86b93leu1gttz5j862h" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is quite easy to deploy your functions. After installing Altogic CLI, you first need to log in to your Altogic Account.&lt;/p&gt;

&lt;p&gt;Your session information will be locally stored so that you do not need to log in again until you log out from your active session.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MSPpoHJL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.circle.so/8ulqfoqiyzqfbret2q2lcgw51xyp" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MSPpoHJL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.circle.so/8ulqfoqiyzqfbret2q2lcgw51xyp" alt="https://cdn.circle.so/8ulqfoqiyzqfbret2q2lcgw51xyp" width="840" height="410"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once logged in, you can create your full-code function. It will first ask you to select the application you want to create the function for. Following app selection, you need to provide a name to your function and select the runtime environment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xXnHe476--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.circle.so/go6uirw2oy141kiau4f7vhdqvj4g" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xXnHe476--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.circle.so/go6uirw2oy141kiau4f7vhdqvj4g" alt="https://cdn.circle.so/go6uirw2oy141kiau4f7vhdqvj4g" width="880" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The create function command will create a folder in your current directory using the name of your function and it will also create an altogic.json file to keep the configuration parameters.&lt;/p&gt;

&lt;p&gt;You can use your code editor to write the code for your function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---d6xRgOk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.circle.so/f8vlw68rinfntybhcyprlgq51gwq" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---d6xRgOk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.circle.so/f8vlw68rinfntybhcyprlgq51gwq" alt="https://cdn.circle.so/f8vlw68rinfntybhcyprlgq51gwq" width="880" height="379"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After completing the code of your function, you can easily deploy it to your application environment.&lt;/p&gt;

&lt;p&gt;When you run the deploy command, Altogic creates a new image and applies this image to your app's execution environment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2aXcwXYT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.circle.so/x6mkne19ybl2q2ucz0gf9gau590f" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2aXcwXYT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.circle.so/x6mkne19ybl2q2ucz0gf9gau590f" alt="https://cdn.circle.so/x6mkne19ybl2q2ucz0gf9gau590f" width="880" height="405"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It may take a couple of minutes to build and deploy your function. You can run altogic get builds and altogic get deployments to get the status of your builds and deployments, respectively.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p8X47ZSg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.circle.so/pu9ohbe99hfohlqctpqs33z7pgf8" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p8X47ZSg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.circle.so/pu9ohbe99hfohlqctpqs33z7pgf8" alt="https://cdn.circle.so/pu9ohbe99hfohlqctpqs33z7pgf8" width="880" height="453"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After writing and successfully deploying your function to your execution environment, you need to link your function to an endpoint, message queue, and/or scheduled task. You can use Altogic Designer to configure your endpoint, message queue, and cron job handlers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uJ891jL5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.circle.so/7nrf4br3mcx58rbkyyx808epmxn2" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uJ891jL5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.circle.so/7nrf4br3mcx58rbkyyx808epmxn2" alt="https://cdn.circle.so/7nrf4br3mcx58rbkyyx808epmxn2" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also test your functions locally. The start command will launch a local HTTP server and provide you the endpoint of the function. The start command has hot-reloading capabilities. It will watch for any changes to your files and restart the HTTP server.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NlNDMlpB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.circle.so/jo4dpnofzyp7k295n7rgdfa66vq6" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NlNDMlpB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.circle.so/jo4dpnofzyp7k295n7rgdfa66vq6" alt="https://cdn.circle.so/jo4dpnofzyp7k295n7rgdfa66vq6" width="880" height="358"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can use &lt;strong&gt;&lt;a href="https://tester.altogic.com/"&gt;Altogic Tester&lt;/a&gt;&lt;/strong&gt; or any other API testing tool (e.g., Postman) to test your serverless functions. In your function code, you can log messages using console.log method. Upon execution of your deployed function, these log messages are also returned in response body.&lt;/p&gt;

&lt;p&gt;We are quite excited to see what you will be building with Altogic serverless functions. If you have questions about Altogic serverless functions or want to share what you have built, please post a message in our &lt;strong&gt;&lt;a href="https://community.altogic.com/"&gt;community forum&lt;/a&gt;&lt;/strong&gt; or &lt;strong&gt;&lt;a href="https://discord.com/invite/ERK2ssumh8"&gt;discord channel&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>news</category>
    </item>
    <item>
      <title>Announcing General Availability of Altogic🚀</title>
      <dc:creator>Deniz</dc:creator>
      <pubDate>Thu, 01 Sep 2022 13:21:02 +0000</pubDate>
      <link>https://dev.to/altogic/announcing-general-availability-of-altogic-503</link>
      <guid>https://dev.to/altogic/announcing-general-availability-of-altogic-503</guid>
      <description>&lt;p&gt;After nearly a year of improving our product during our public beta phase, we have great pleasure in announcing that Altogic is now &lt;strong&gt;Generally Available&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;It has taken us over a year to get to where we are today, with a tremendous amount of work being contributed by our team to build the &lt;strong&gt;Altogic platform&lt;/strong&gt; and &lt;strong&gt;developer community&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;As of today, with the announcement of general availability, we are also launching our environment-based pricing plans.&lt;/p&gt;

&lt;h2&gt;
  
  
  New execution clusters worldwide
&lt;/h2&gt;

&lt;p&gt;We are launching 10 new execution clusters all over the world. Now you can deploy your apps in &lt;strong&gt;US Central (Iowa), US East (South Carolina), US West (Oregon), Montreal, São Paulo, London, Frankfurt, Mumbai, Singapore&lt;/strong&gt; and &lt;strong&gt;Sydney&lt;/strong&gt; to minimize latencies for your target users.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CLFJpdEv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z7i0ns9qh4tc21kmrzci.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CLFJpdEv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z7i0ns9qh4tc21kmrzci.png" alt="New execution clusters" width="880" height="587"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Launching the new website
&lt;/h2&gt;

&lt;p&gt;During the '&lt;strong&gt;Public Beta&lt;/strong&gt;' phase, we received valuable feedback, and with the '&lt;strong&gt;General Availability,&lt;/strong&gt;' we have renewed and rebuilt a brand new website. It is now more developer friendly, including code snippets, easy-to-access links, a help center, and last but not the least has the dark mode.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sdKFsLLb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3n6t1isq77y692ql2c12.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sdKFsLLb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3n6t1isq77y692ql2c12.png" alt="New Altogic website" width="880" height="587"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  New documentation sites
&lt;/h2&gt;

&lt;p&gt;To substantially ease developers' onboarding and development experience in Altogic, we are now serving more resources; optimized, updated, cleaner, and easy-to-use &lt;a href="https://www.altogic.com/docs"&gt;product guides&lt;/a&gt;, &lt;a href="https://www.altogic.com/client"&gt;client library guide&lt;/a&gt;, and &lt;a href="https://clientapi.altogic.com/v2.1.0/modules.html"&gt;API reference&lt;/a&gt; documentation. These contain instructions, quick start guides, best practices, code examples, and more. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6OidWYsp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6s0s16n2bezxo70r7tcw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6OidWYsp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6s0s16n2bezxo70r7tcw.png" alt="New Altogic documentations" width="880" height="587"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  New resources for developers: Showcase Apps &amp;amp; Blog
&lt;/h2&gt;

&lt;p&gt;We are launching the &lt;a href="https://www.altogic.com/showcase"&gt;showcase site&lt;/a&gt; to highlight specific aspects of the platform and usage scenarios in Altogic and to encourage the developers to submit their apps that are developed with Altogic. With the showcase app, you can access the demo apps, their full front-end source code and technical blogs.&lt;/p&gt;

&lt;p&gt;To disseminate know-how, help our audience, come up with different ideas and add value to the developer community, we are also launching our brand new &lt;a href="https://www.altogic.com/blog"&gt;blog site&lt;/a&gt; where we will be posting technical articles, how-to guides and new feature updates.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J3Py8tCr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fx1ki19srq9fydgmd8rb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J3Py8tCr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fx1ki19srq9fydgmd8rb.png" alt="New showcase and blog sites" width="880" height="587"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Launch of our pricing plans
&lt;/h2&gt;

&lt;p&gt;With the General Availability, we are launching our environment based pricing plans. We will continue to have a Free plan where you will be able to develop and prototype your applications. Our free plan does not have any limitations on the functionality front. You will be able to use all platform features, yet the free plan will have specific usage quotas. For more information on our pricing plans please visit the &lt;a href="https://www.altogic.com/pricing"&gt;Pricing&lt;/a&gt; section on our new website.&lt;/p&gt;

&lt;p&gt;Exciting times are ahead of us and we are looking forward to hearing about your Altogic experiences. Thank you so much for your time and support without which we wouldn’t have done this.&lt;/p&gt;

</description>
      <category>news</category>
      <category>startup</category>
      <category>community</category>
      <category>tooling</category>
    </item>
    <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 implement Two-Factor Authentication using Next.js, Twilio and Altogic</title>
      <dc:creator>Mert Yerekapan</dc:creator>
      <pubDate>Fri, 13 May 2022 12:43:23 +0000</pubDate>
      <link>https://dev.to/altogic/how-to-implement-two-factor-authentication-using-nextjs-twilio-and-altogic-ok0</link>
      <guid>https://dev.to/altogic/how-to-implement-two-factor-authentication-using-nextjs-twilio-and-altogic-ok0</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This article will cover &lt;strong&gt;two-factor authentication&lt;/strong&gt; basics using &lt;a href="https://nextjs.org/" rel="noopener noreferrer"&gt;Next.js&lt;/a&gt;, &lt;a href="https://twilio.com/" rel="noopener noreferrer"&gt;Twilio&lt;/a&gt;, and &lt;a href="https://altogic.com/" rel="noopener noreferrer"&gt;Altogic&lt;/a&gt;, a Backend-as-a-Service platform using its client library. This authentication method allows users to add one more security layer to their application. Many people enable their &lt;strong&gt;two-factor authentication&lt;/strong&gt; settings to increase their security using their phone numbers or authentication apps for security purposes.&lt;/p&gt;

&lt;p&gt;You can check out the &lt;a href="https://github.com/altogic/altogic/tree/main/examples/nextjs-two-factor-authentication" rel="noopener noreferrer"&gt;source code&lt;/a&gt; and &lt;a href="https://altogic-nextjs-two-factor-auth.vercel.app/" rel="noopener noreferrer"&gt;demo app&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  How is the two-factor authentication flow?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Users who already have an account need to set their phone number to enable two-factor authentication.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An SMS with a code is sent to the specified phone number by &lt;strong&gt;Altogic and Twilio&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Users verify their phone number by entering the code sent to their phone number.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Users can enable or disable the two-factor authentication setting from their profile.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When users try to sign in, if two-factor authentication is enabled, a code is sent to the specified phone number by &lt;strong&gt;Altogic and Twilio.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Users verify their identity by entering the code on the input on the screen.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If two-factor authentication is not enabled, they can sign in without this process.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Youtube Showcase Video
&lt;/h2&gt;

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

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

&lt;p&gt;This project builds on top of the complete e-mail authentication app we created previously. You can follow the &lt;a href="https://medium.com/altogic/altogic-email-authentication-with-next-js-and-altogic-4c036c36ea8f" rel="noopener noreferrer"&gt;tutorial&lt;/a&gt; to build the same app or clone the project from &lt;a href="https://github.com/altogic/altogic/tree/main/examples/nextjs-email-authentication" rel="noopener noreferrer"&gt;here&lt;/a&gt; and continue with the rest of the tutorial.&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 use the free trial, you will need to take the &lt;strong&gt;Twilio&lt;/strong&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 on &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 “Get a trial phone number” 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%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AFjkgv5P9FCTkF62u.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%2Fcdn-images-1.medium.com%2Fmax%2F2800%2F0%2AFjkgv5P9FCTkF62u.png" alt="Twilio Credentials"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we’ve copied the configuration credentials to the clipboard. You must specify the verified phone numbers in trial accounts, 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;/li&gt;
&lt;li&gt;&lt;p&gt;Be sure that &lt;strong&gt;Messaging&lt;/strong&gt; and &lt;strong&gt;Phone Numbers&lt;/strong&gt; products are selected.&lt;/p&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AuyjZHk6tFYytA34Y.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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2AuyjZHk6tFYytA34Y.png"&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A-PLQ3y-NeudqR2hg.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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F0%2A-PLQ3y-NeudqR2hg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Create the models
&lt;/h2&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;/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%2Fcdn-images-1.medium.com%2Fmax%2F3590%2F0%2AjOvv0K2lUO1dk6Ro" 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%2Fcdn-images-1.medium.com%2Fmax%2F3590%2F0%2AjOvv0K2lUO1dk6Ro" alt="Key entities in Altogic"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When we create our application, &lt;strong&gt;a user model is created&lt;/strong&gt; by default. We need to add a &lt;strong&gt;boolean field&lt;/strong&gt; to this user model to let users &lt;strong&gt;enable&lt;/strong&gt; and &lt;strong&gt;disable&lt;/strong&gt; the two-factor authentication.&lt;/p&gt;

&lt;p&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;/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%2Fcdn-images-1.medium.com%2Fmax%2F5368%2F1%2AwNMd344wRFEmdVWm-WXppg%402x.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%2Fcdn-images-1.medium.com%2Fmax%2F5368%2F1%2AwNMd344wRFEmdVWm-WXppg%402x.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;In the model details view, select &lt;strong&gt;New field.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;From the dropdown menu, &lt;strong&gt;select&lt;/strong&gt; the &lt;strong&gt;Boolean&lt;/strong&gt; that you would like to create.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the field name, type “&lt;strong&gt;twoFactorAuth&lt;/strong&gt;” and set a default value of false&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &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%2Fcdn-images-1.medium.com%2Fmax%2F2392%2F1%2AvbZntcm568IFmlTnqFn00g%402x.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%2Fcdn-images-1.medium.com%2Fmax%2F2392%2F1%2AvbZntcm568IFmlTnqFn00g%402x.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We need to create a new model called &lt;strong&gt;phoneVerificationCode&lt;/strong&gt; to handle the verification code we send to users’ phone numbers. This data type will be a &lt;strong&gt;Transient&lt;/strong&gt; data type meaning it is not stored in the database. We are defining it as &lt;strong&gt;Transient&lt;/strong&gt; because we don’t need it after completing the verification.&lt;/p&gt;

&lt;p&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;/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%2Fcdn-images-1.medium.com%2Fmax%2F5364%2F1%2AsDm3NGTyXTUxQryR4Wb2fw%402x.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%2Fcdn-images-1.medium.com%2Fmax%2F5364%2F1%2AsDm3NGTyXTUxQryR4Wb2fw%402x.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After, you can pick a &lt;strong&gt;Model&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%2Fcdn-images-1.medium.com%2Fmax%2F2392%2F1%2A6VQM6b2shrdweT_o80UTfQ%402x.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%2Fcdn-images-1.medium.com%2Fmax%2F2392%2F1%2A6VQM6b2shrdweT_o80UTfQ%402x.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And create the &lt;strong&gt;phoneVerificationCode&lt;/strong&gt; model. Afterward, we need to add three fields:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;code&lt;/strong&gt; field, which is an &lt;strong&gt;Integer&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;userId&lt;/strong&gt; field, which is an &lt;strong&gt;Object reference&lt;/strong&gt; to the &lt;strong&gt;users&lt;/strong&gt; model.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;phoneNumber&lt;/strong&gt; field, which is a &lt;strong&gt;Text&lt;/strong&gt; field.&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%2Fcdn-images-1.medium.com%2Fmax%2F5360%2F1%2AiE7PaDia0KjitAUL75EE9A%402x.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%2Fcdn-images-1.medium.com%2Fmax%2F5360%2F1%2AiE7PaDia0KjitAUL75EE9A%402x.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Create the endpoints
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Endpoints&lt;/strong&gt; are the communication channels to access the services provided in your applications, and through endpoints, you &lt;strong&gt;expose&lt;/strong&gt; your application services and data &lt;strong&gt;to the outside world&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;To create an endpoint via the Designer, you need to navigate the &lt;strong&gt;Endpoints view&lt;/strong&gt; in designer and select &lt;strong&gt;New-&amp;gt;Endpoint.&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%2Fcdn-images-1.medium.com%2Fmax%2F10240%2F1%2Al4aFW2BIB7BvOVo7V35RvQ.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%2Fcdn-images-1.medium.com%2Fmax%2F10240%2F1%2Al4aFW2BIB7BvOVo7V35RvQ.png" alt="How to create endpoints in Altogic Designer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After clicking, you need to enter a relevant endpoint name and optionally pick a group, pick a method, specify the path and assign a service that handles the requests to the endpoint.&lt;/p&gt;

&lt;p&gt;We can also click on the “Session required” checkbox, which enforces a need for a session when a request is made to the endpoint.&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%2Fcdn-images-1.medium.com%2Fmax%2F2384%2F1%2A29q_MAhK1YNGR8lz8XmawQ%402x.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%2Fcdn-images-1.medium.com%2Fmax%2F2384%2F1%2A29q_MAhK1YNGR8lz8XmawQ%402x.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this example, our method is “&lt;strong&gt;POST&lt;/strong&gt;,” and our path is “&lt;strong&gt;/users/set-phone&lt;/strong&gt;” meaning that if we send a &lt;strong&gt;POST&lt;/strong&gt; request to this path, the service we define will run. We created a service by clicking “&lt;strong&gt;Add new service&lt;/strong&gt;” and by naming our service, we will be created an empty service. We will design the service next.&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%2Fcdn-images-1.medium.com%2Fmax%2F2384%2F1%2A6q82ovkRXn1WhRQetBXn-w%402x.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%2Fcdn-images-1.medium.com%2Fmax%2F2384%2F1%2A6q82ovkRXn1WhRQetBXn-w%402x.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will create &lt;strong&gt;three more endpoints&lt;/strong&gt; to verify the code while changing the phone, signing in, and implementing the particular sign-in functionality.&lt;/p&gt;

&lt;p&gt;Create the verify code during changing phone endpoint:&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%2Fcdn-images-1.medium.com%2Fmax%2F2380%2F1%2A5GPJRB0kJ_ig2iFsiEIFeg%402x.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%2Fcdn-images-1.medium.com%2Fmax%2F2380%2F1%2A5GPJRB0kJ_ig2iFsiEIFeg%402x.png" alt="Verify code during changing phone endpoint"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create the verify code during the sign-in endpoint:&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%2Fcdn-images-1.medium.com%2Fmax%2F2384%2F1%2AvCLguYn61c4uREcRAlUpfQ%402x.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%2Fcdn-images-1.medium.com%2Fmax%2F2384%2F1%2AvCLguYn61c4uREcRAlUpfQ%402x.png" alt="Verify code during sign-in endpoint"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create the sign-in endpoint for implementing the particular 2-FA logic:&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%2Fcdn-images-1.medium.com%2Fmax%2F2392%2F1%2AebDWbWzWx2uoAMR5SKvCrg%402x.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%2Fcdn-images-1.medium.com%2Fmax%2F2392%2F1%2AebDWbWzWx2uoAMR5SKvCrg%402x.png" alt="Sign in endpoint for implementing the specific 2-FA logic"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we created our endpoints and services, we can start &lt;strong&gt;designing&lt;/strong&gt; the services, which is the &lt;strong&gt;most fun part&lt;/strong&gt; of using &lt;strong&gt;Altogic&lt;/strong&gt;!&lt;/p&gt;

&lt;h2&gt;
  
  
  Design the Services
&lt;/h2&gt;

&lt;p&gt;Building the flow of service involves three main activities.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Adding the right node from the &lt;strong&gt;nodes library&lt;/strong&gt; to the &lt;strong&gt;service flow area.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Customizing the added node parameters using the &lt;strong&gt;node properties panel.&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Linking the &lt;strong&gt;output link point&lt;/strong&gt; of a node to the &lt;strong&gt;input link point&lt;/strong&gt; of another node using relations.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;First, we will implement the &lt;strong&gt;“Set phone number service.”&lt;/strong&gt; We have the start node, which is used to start the execution of the endpoint handling service. It runs only once at the start of the service to trigger nodes connected to its output link point. We define a query string parameter of type text named “phoneNumber” as input for this endpoint.&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%2Fcdn-images-1.medium.com%2Fmax%2F2924%2F1%2AnkDzaz6-j9lRJT53Bc22SA.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%2Fcdn-images-1.medium.com%2Fmax%2F2924%2F1%2AnkDzaz6-j9lRJT53Bc22SA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, we check if the phone number sent is a valid phone number with the &lt;strong&gt;ISMOBILEPHONE()&lt;/strong&gt; function.&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%2Fcdn-images-1.medium.com%2Fmax%2F3052%2F1%2AD-_W4oUTdXQkizH4ZWiCXg.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%2Fcdn-images-1.medium.com%2Fmax%2F3052%2F1%2AD-_W4oUTdXQkizH4ZWiCXg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If no, return an error response.&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%2Fcdn-images-1.medium.com%2Fmax%2F2916%2F1%2AA1CFsOtXQZaDurzdaN8Yzg.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%2Fcdn-images-1.medium.com%2Fmax%2F2916%2F1%2AA1CFsOtXQZaDurzdaN8Yzg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If yes, create an object of &lt;strong&gt;phoneVerificationCode&lt;/strong&gt; model. For code, we generate a random number with &lt;strong&gt;RANDBETWEEN()&lt;/strong&gt; function and insert the other fields from either the input or the session.&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%2Fcdn-images-1.medium.com%2Fmax%2F3044%2F1%2ALKXs8nX-jsK_wG2y-nxuRw.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%2Fcdn-images-1.medium.com%2Fmax%2F3044%2F1%2ALKXs8nX-jsK_wG2y-nxuRw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cache the object we created so we can access it later for verifying the code. I want the code to expire after one minute, so I set the timeout value to 1 minute.&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%2Fcdn-images-1.medium.com%2Fmax%2F3228%2F1%2AHR3DBjnvxS2kIVQtR6H7FA.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%2Fcdn-images-1.medium.com%2Fmax%2F3228%2F1%2AHR3DBjnvxS2kIVQtR6H7FA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Send the SMS message to the specified phone number with the code. Here we use the Twilio credentials we obtained.&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%2Fcdn-images-1.medium.com%2Fmax%2F3120%2F1%2AB3JEBKCDPgUHRyXPBUcrHQ.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%2Fcdn-images-1.medium.com%2Fmax%2F3120%2F1%2AB3JEBKCDPgUHRyXPBUcrHQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we return the success response. This is the final look of our service:&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%2Fcdn-images-1.medium.com%2Fmax%2F3316%2F1%2AzcPAj4TcKj0-0fs6krdOvw.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%2Fcdn-images-1.medium.com%2Fmax%2F3316%2F1%2AzcPAj4TcKj0-0fs6krdOvw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we will implement the &lt;strong&gt;“Verify code in change phone service.”&lt;/strong&gt; This service is used to verify the code when users want to change their phone numbers.&lt;/p&gt;

&lt;p&gt;We have the start node, which is used to start the execution of the endpoint handling service. It runs only once at the start of the service to trigger nodes connected to its output link point. We define the request body structure as a single model of “&lt;strong&gt;phoneVerificationCode&lt;/strong&gt;” as input for this endpoint.&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%2Fcdn-images-1.medium.com%2Fmax%2F2940%2F1%2ARNo9Q67RMaiKk1hWMY36nw.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%2Fcdn-images-1.medium.com%2Fmax%2F2940%2F1%2ARNo9Q67RMaiKk1hWMY36nw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Get the cached object with the phone number to check the code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2936%2F1%2Aa9xgDJadobGlYRWCCS5CiQ.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%2Fcdn-images-1.medium.com%2Fmax%2F2936%2F1%2Aa9xgDJadobGlYRWCCS5CiQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Return an error response if the cached object does not exist anymore. It means that the code is expired and no longer valid.&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%2Fcdn-images-1.medium.com%2Fmax%2F2844%2F1%2AMVUdDWSl5nQeschEDgnn7Q.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%2Fcdn-images-1.medium.com%2Fmax%2F2844%2F1%2AMVUdDWSl5nQeschEDgnn7Q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check if the cached code is &lt;strong&gt;equal&lt;/strong&gt; to the code sent in the “&lt;strong&gt;phoneVerificationCode&lt;/strong&gt;” object.&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%2Fcdn-images-1.medium.com%2Fmax%2F2976%2F1%2AMyE-KwLMtZt0n5HT9I-DsQ.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%2Fcdn-images-1.medium.com%2Fmax%2F2976%2F1%2AMyE-KwLMtZt0n5HT9I-DsQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Update the user's phone number and set the “&lt;strong&gt;phoneVerified&lt;/strong&gt;” to true using the “&lt;strong&gt;Update Object Fields by Id&lt;/strong&gt;” node. We need to set the updated object model to “&lt;strong&gt;users&lt;/strong&gt;” and object id to the userId, and we do that by giving the &lt;strong&gt;userId&lt;/strong&gt; we obtain from &lt;strong&gt;phoneVerificationCode&lt;/strong&gt; object.&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%2Fcdn-images-1.medium.com%2Fmax%2F2932%2F1%2AW-x8CF5gbpXvPusHGMA5TA.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%2Fcdn-images-1.medium.com%2Fmax%2F2932%2F1%2AW-x8CF5gbpXvPusHGMA5TA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we return the success response. This is the final look of our service:&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%2Fcdn-images-1.medium.com%2Fmax%2F2932%2F1%2Ak9o3tH28zaHaeJpKL_droA%402x.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%2Fcdn-images-1.medium.com%2Fmax%2F2932%2F1%2Ak9o3tH28zaHaeJpKL_droA%402x.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we will implement the &lt;strong&gt;“Verify code in sign-in service.”&lt;/strong&gt; This service is used to verify the code when users try to sign in when their two-factor authentication is enabled.&lt;/p&gt;

&lt;p&gt;We have the start node, which is used to start the execution of the endpoint handling service. It runs only once at the start of the service to trigger nodes connected to its output link point. We define the request body structure as a single model of “&lt;strong&gt;phoneVerificationCode&lt;/strong&gt;” as input for this endpoint.&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%2Fcdn-images-1.medium.com%2Fmax%2F2780%2F1%2Ak2FpvseVrlnmQgLil6nT2g.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%2Fcdn-images-1.medium.com%2Fmax%2F2780%2F1%2Ak2FpvseVrlnmQgLil6nT2g.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Get the cached object with the phone number to check the code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2912%2F1%2ArC2PZbcgE_9WqmJ4gCbObQ.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%2Fcdn-images-1.medium.com%2Fmax%2F2912%2F1%2ArC2PZbcgE_9WqmJ4gCbObQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Return an error response if the cached object does not exist anymore. It means that the code is expired and no longer valid.&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%2Fcdn-images-1.medium.com%2Fmax%2F2844%2F1%2AMVUdDWSl5nQeschEDgnn7Q.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%2Fcdn-images-1.medium.com%2Fmax%2F2844%2F1%2AMVUdDWSl5nQeschEDgnn7Q.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check if the cached code is &lt;strong&gt;equal&lt;/strong&gt; to the code sent in the “&lt;strong&gt;phoneVerificationCode&lt;/strong&gt;” object.&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%2Fcdn-images-1.medium.com%2Fmax%2F2936%2F1%2AJmd6ST-imyKzq7mshzZIoA.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%2Fcdn-images-1.medium.com%2Fmax%2F2936%2F1%2AJmd6ST-imyKzq7mshzZIoA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Return error if code is not equal to the one sent in the input.&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%2Fcdn-images-1.medium.com%2Fmax%2F2860%2F1%2ArgvY5C6syY_Ty7ZynInoMg.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%2Fcdn-images-1.medium.com%2Fmax%2F2860%2F1%2ArgvY5C6syY_Ty7ZynInoMg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Get the user using the “&lt;strong&gt;Get Single Object by Query&lt;/strong&gt;” node. We need to set the &lt;strong&gt;retrieved object model&lt;/strong&gt; to &lt;strong&gt;users,&lt;/strong&gt; and our query should be this.phone==inputObject.phoneNumber to get the user with the specified phone.&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%2Fcdn-images-1.medium.com%2Fmax%2F2912%2F1%2Asr7d0cpMHrA0R5QRARRhLw.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%2Fcdn-images-1.medium.com%2Fmax%2F2912%2F1%2Asr7d0cpMHrA0R5QRARRhLw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If there is no user, return an error response.&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%2Fcdn-images-1.medium.com%2Fmax%2F2708%2F1%2ADLpzhDesjEV1F6FMF8V_Fw.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%2Fcdn-images-1.medium.com%2Fmax%2F2708%2F1%2ADLpzhDesjEV1F6FMF8V_Fw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If there is a user, create a user session.&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%2Fcdn-images-1.medium.com%2Fmax%2F2864%2F1%2A1MUgIL6ewWHScyPljyKDEg.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%2Fcdn-images-1.medium.com%2Fmax%2F2864%2F1%2A1MUgIL6ewWHScyPljyKDEg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we return the success response. This is the final look of our service:&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%2Fcdn-images-1.medium.com%2Fmax%2F3372%2F1%2AnX5kVhHiQ5sKap6py5R32g%402x.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%2Fcdn-images-1.medium.com%2Fmax%2F3372%2F1%2AnX5kVhHiQ5sKap6py5R32g%402x.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we will implement the &lt;strong&gt;“Sign in service.”&lt;/strong&gt; This service is used to implement the sign-in feature. Because we want to use two-factor authentication, we can’t use the function in the client library, and we have to design it ourselves. But don’t worry, designing complex business logic in &lt;strong&gt;Altogic&lt;/strong&gt; is relatively easy! :)&lt;/p&gt;

&lt;p&gt;We have the start node, which is used to start the execution of the endpoint handling service. It runs only once at the start of the service to trigger nodes connected to its output link point. We define a query string parameter of type email named “&lt;strong&gt;email&lt;/strong&gt;” and type text called “&lt;strong&gt;password&lt;/strong&gt;” as input for this endpoint.&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%2Fcdn-images-1.medium.com%2Fmax%2F3024%2F1%2AgEt0rT29AtvAVAWMcvRRug.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%2Fcdn-images-1.medium.com%2Fmax%2F3024%2F1%2AgEt0rT29AtvAVAWMcvRRug.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Get the user using the “&lt;strong&gt;Get Single Object by Query&lt;/strong&gt;” node. We need to set the &lt;strong&gt;retrieved object model&lt;/strong&gt; to &lt;strong&gt;users,&lt;/strong&gt; and our query should be this.email==params.body.email to get the user with the specified email.&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%2Fcdn-images-1.medium.com%2Fmax%2F2856%2F1%2AvXyzYdQd-IXo9RNPrRavBQ.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%2Fcdn-images-1.medium.com%2Fmax%2F2856%2F1%2AvXyzYdQd-IXo9RNPrRavBQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Return an error if there is no user with the specified email.&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%2Fcdn-images-1.medium.com%2Fmax%2F2640%2F1%2AsmuLN2HkfsNLmtQnunwdBw.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%2Fcdn-images-1.medium.com%2Fmax%2F2640%2F1%2AsmuLN2HkfsNLmtQnunwdBw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Use the &lt;strong&gt;“If-Else Condition&lt;/strong&gt;” node to check if the emailVerified field of the user is true or not.&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%2Fcdn-images-1.medium.com%2Fmax%2F2804%2F1%2ApJis4ccGRiuOmE4eoIuLiQ.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%2Fcdn-images-1.medium.com%2Fmax%2F2804%2F1%2ApJis4ccGRiuOmE4eoIuLiQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If the email is not verified, return an error response.&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%2Fcdn-images-1.medium.com%2Fmax%2F2816%2F1%2AkkDs3gEcOUf3s819Mft_gA.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%2Fcdn-images-1.medium.com%2Fmax%2F2816%2F1%2AkkDs3gEcOUf3s819Mft_gA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Compare the password sent with the password in the database with &lt;strong&gt;ECOMPARE()&lt;/strong&gt; function. This function compares the password text in the input with the password in the database but &lt;strong&gt;does not expose&lt;/strong&gt; the encrypted password. No one, including the developer, can see the user's passwords.&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%2Fcdn-images-1.medium.com%2Fmax%2F2836%2F1%2AV5SaHpMIjVkA5MncU74Mqw.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%2Fcdn-images-1.medium.com%2Fmax%2F2836%2F1%2AV5SaHpMIjVkA5MncU74Mqw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Return an error response if passwords do not match.&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%2Fcdn-images-1.medium.com%2Fmax%2F2744%2F1%2AGwqEcn7G3izZMxJRUry-Fw.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%2Fcdn-images-1.medium.com%2Fmax%2F2744%2F1%2AGwqEcn7G3izZMxJRUry-Fw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check if the &lt;strong&gt;two-factor authentication&lt;/strong&gt; of the user is enabled.&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%2Fcdn-images-1.medium.com%2Fmax%2F2648%2F1%2A-K5POX5meS0vgJYMCG7ZGg.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%2Fcdn-images-1.medium.com%2Fmax%2F2648%2F1%2A-K5POX5meS0vgJYMCG7ZGg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If two-factor authentication of the user is not enabled, create the user session and return it with the user data.&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%2Fcdn-images-1.medium.com%2Fmax%2F2852%2F1%2AHN4mcUgqwbM3N-MgugRmwg.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%2Fcdn-images-1.medium.com%2Fmax%2F2852%2F1%2AHN4mcUgqwbM3N-MgugRmwg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If enabled, create an object of &lt;strong&gt;phoneVerificationCode&lt;/strong&gt; model. For code, we generate a random number with &lt;strong&gt;RANDBETWEEN()&lt;/strong&gt; function and insert the other fields from the input.&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%2Fcdn-images-1.medium.com%2Fmax%2F3284%2F1%2AEZAwI3iGsquthZ8syGCwcw.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%2Fcdn-images-1.medium.com%2Fmax%2F3284%2F1%2AEZAwI3iGsquthZ8syGCwcw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cache the object we created so we can access it later for verifying the code. I want the code to expire after one minute, so I set the timeout value to 1 minute.&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%2Fcdn-images-1.medium.com%2Fmax%2F2996%2F1%2AKCckXGETVD4z3I-Fzg6W4w.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%2Fcdn-images-1.medium.com%2Fmax%2F2996%2F1%2AKCckXGETVD4z3I-Fzg6W4w.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Send the SMS message to the specified phone number with the code. Here we use the Twilio credentials we obtained.&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%2Fcdn-images-1.medium.com%2Fmax%2F2924%2F1%2AhG0LEpSjCwtYbrcUFm4MOQ.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%2Fcdn-images-1.medium.com%2Fmax%2F2924%2F1%2AhG0LEpSjCwtYbrcUFm4MOQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we return the success response. This is the final look of our service:&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%2Fcdn-images-1.medium.com%2Fmax%2F4916%2F1%2A_FPVaXTVi8QhUZoGVuNqTA.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%2Fcdn-images-1.medium.com%2Fmax%2F4916%2F1%2A_FPVaXTVi8QhUZoGVuNqTA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To learn more about building the service flows, check out the &lt;a href="https://docs.altogic.com/help-guides/building-services/service-flow" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let’s Start Coding!
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Set/Change phone functionality
&lt;/h3&gt;

&lt;p&gt;To enable two-factor authentication, users need to set up their phone numbers. This functionality is the same as &lt;strong&gt;changing the phone functionality&lt;/strong&gt; so that we will use the same screen with some minor conditional UI changes.&lt;/p&gt;

&lt;p&gt;We have already created the endpoint and designed the service. We need to send a request to the endpoint using &lt;strong&gt;Altogic Client Library&lt;/strong&gt; using &lt;strong&gt;EndpointManager&lt;/strong&gt; and the post method like &lt;strong&gt;altogic.endpoint.post()&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  SMS verify during change phone functionality
&lt;/h3&gt;

&lt;p&gt;Code above runs the service for setting/changing the phone number and sending the SMS for verification code. Now, users need a screen to enter the SMS code. We have already created the endpoint and designed the service for this case. We need to send a request to that particular endpoint.&lt;/p&gt;

&lt;p&gt;Here is the code for that:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Toggle Two Factor Authentication functionality
&lt;/h3&gt;

&lt;p&gt;Users should be able to switch on and off two-factor authentication if they want to. For this, we are implementing a basic switch. We are updating the &lt;strong&gt;twoFactorAuth&lt;/strong&gt; boolean field.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Sign in functionality
&lt;/h3&gt;

&lt;p&gt;When users want to sign in, we will use the service we designed because we need to check if two-factor authentication is enabled and if yes, we need to send an SMS with a code. We replace the client library function with sending a request to the endpoint.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  SMS verify during sign-in functionality
&lt;/h3&gt;

&lt;p&gt;Code above runs the service for signing in and sending the SMS for verification code. Now, users need a screen to enter the SMS code. We have already created the endpoint and designed the service for this case. We need to send a request to that particular endpoint with &lt;strong&gt;code&lt;/strong&gt;, &lt;strong&gt;phone&lt;/strong&gt; &lt;strong&gt;number,&lt;/strong&gt; and &lt;strong&gt;userId&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here is the code for that:&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 adding the two-factor authentication method to our email authentication app using &lt;a href="https://nextjs.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;Next.js&lt;/strong&gt;&lt;/a&gt;, &lt;a href="https://twilio.com/" rel="noopener noreferrer"&gt;&lt;strong&gt;Twilio&lt;/strong&gt;&lt;/a&gt;, and &lt;a href="https://clientapi.altogic.com/v1.3.1/modules.html" rel="noopener noreferrer"&gt;&lt;strong&gt;Altogic Client Library&lt;/strong&gt;&lt;/a&gt;. Thanks to &lt;a href="https://altogic.com/" rel="noopener noreferrer"&gt;&lt;strong&gt;Altogic&lt;/strong&gt;&lt;/a&gt;, we can build this 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/nextjs-two-factor-authentication" rel="noopener noreferrer"&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>webdev</category>
      <category>react</category>
      <category>nextjs</category>
    </item>
    <item>
      <title>Backend Basics: RESTful API (API, REST, Methods, JSON, Examples)</title>
      <dc:creator>Erkin Yılmaz</dc:creator>
      <pubDate>Tue, 10 May 2022 10:39:03 +0000</pubDate>
      <link>https://dev.to/altogic/backend-basics-restful-api-api-rest-methods-json-examples-25nj</link>
      <guid>https://dev.to/altogic/backend-basics-restful-api-api-rest-methods-json-examples-25nj</guid>
      <description>&lt;p&gt;As you probably know, a typical modern application consists of 2 main parts: Frontend and Backend.&lt;/p&gt;

&lt;p&gt;If you want to create a web or mobile app, you need to have at least a basic understanding of REST API which is commonly used on backend development.&lt;/p&gt;

&lt;p&gt;Todays technology enables developers to create complex backend apps using these simple concepts in no time by using BaaS platforms like &lt;a href="https://altogic.com" rel="noopener noreferrer"&gt;Altogic.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  RESTful API
&lt;/h2&gt;

&lt;p&gt;Let’s break it down and understand the REST &amp;amp; API terms.&lt;/p&gt;

&lt;h3&gt;
  
  
  Italian Restaurant Metaphor
&lt;/h3&gt;

&lt;p&gt;Let’s say you are trying to find nearby Italian restaurants on your favorite restaurant review app. You open up your mobile app, type “Italian” into a search field, hit enter, and you see a list of restaurants near your location.&lt;/p&gt;

&lt;p&gt;A REST API works similarly. You request something, and you get a list of results back from the service you are requesting.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is API?
&lt;/h3&gt;

&lt;p&gt;An API is an Application Programming Interface. It is a set of rules that allow applications to talk to each other. The developer creates the API on the server and allows the client to talk to it.&lt;/p&gt;

&lt;p&gt;In our Italian restaurant example, the server is the application running in the cloud, and the client is the mobile app you use to search for Italian restaurants.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is REST?
&lt;/h3&gt;

&lt;p&gt;REST determines what the API looks like. It stands for “Representational State Transfer,” and it is a set of rules that developers follow when they create their API. In the above example, the search functionality is an API resource exposed by REST.&lt;/p&gt;

&lt;h3&gt;
  
  
  Methods
&lt;/h3&gt;

&lt;p&gt;In RESTful API, the client and server communicate using the HTTP protocol. The client sends a request to the server, and the server processes this request and sends back a response in return.&lt;/p&gt;

&lt;p&gt;Here is the HTTP methods that are commonly used in RESTful APIs:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. GET&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This request is used to get a resource from a server. If you perform a GET request, the server looks for the data you requested and sends it back to you. In other words, a GET request performs a READ operation. This is the default request method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. POST&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This request is used to create a new resource or perform an action on a server. If you perform a POST request, the server creates a new entry in the database or performs an action and tells you whether the creation is successful or returns the action results according to your service design.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. PUT / PATCH&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Primarily used for updating a resource on a server. For example, if you perform a PUT/PATCH request, the server updates an entry in the database and tells you whether the update is successful. In other words, a PUT/PATCH request performs an UPDATE operation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. DELETE&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This request is used to delete a resource from a server. If you perform a DELETE request, the server deletes an entry in the database and tells you whether the deletion is successful. In other words, a DELETE request performs a DELETE operation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Okay, I got it. Can you show me an example usage of RESTful API in an app?
&lt;/h2&gt;

&lt;p&gt;As I told you, todays technology enables developers to create complex backend apps with these simple concepts in no time by using BaaS platforms.&lt;/p&gt;

&lt;p&gt;Let’s see an example with Altogic where we use RESTful API to create our backend app:&lt;/p&gt;

&lt;p&gt;1.Create your database models&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%2Fcdn-images-1.medium.com%2Fmax%2F5412%2F1%2AjmZ9bnjfEaudQX6dkbvKcw.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%2Fcdn-images-1.medium.com%2Fmax%2F5412%2F1%2AjmZ9bnjfEaudQX6dkbvKcw.png" alt="Models tab of Altogic Designer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2.Define your business logic (services)&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%2Fcdn-images-1.medium.com%2Fmax%2F5812%2F1%2ALkWL0i9bFbKkjg9Ne_iTlg.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%2Fcdn-images-1.medium.com%2Fmax%2F5812%2F1%2ALkWL0i9bFbKkjg9Ne_iTlg.png" alt="Defining a service in Altogic Designer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3.Create your &lt;strong&gt;RESTful&lt;/strong&gt; Endpoints and associate them with your services&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%2Fcdn-images-1.medium.com%2Fmax%2F3836%2F1%2Ab9JEk_mR-BU3jOfeo2wdjA.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%2Fcdn-images-1.medium.com%2Fmax%2F3836%2F1%2Ab9JEk_mR-BU3jOfeo2wdjA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this case, when a POST request is sent to the path “&lt;strong&gt;/posts/{postId}/comments&lt;/strong&gt;” (3rd photo), it will trigger the “Add comment to a post service” (2nd photo) which creates a comment object under “comments” model on our database (1st photo) with the input given.&lt;/p&gt;

&lt;p&gt;This is the logic behind your backend apps. You can create complex backend apps and connect them to your frontend using Altogic client library with ease.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is JSON?
&lt;/h3&gt;

&lt;p&gt;JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write.&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%2Fcdn-images-1.medium.com%2Fmax%2F2160%2F0%2AdYnaVrfuE-CcsHJE.jpg" 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%2Fcdn-images-1.medium.com%2Fmax%2F2160%2F0%2AdYnaVrfuE-CcsHJE.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is mainly used to store data in document databases and transport data between different applications, primarily between a server and web applications.&lt;/p&gt;

&lt;p&gt;JSON is also frequently used in &lt;strong&gt;RESTFul APIs&lt;/strong&gt; to provide data in request and response body. Below is an example JSON document summarizing a menu of a restaurant.&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%2Fcdn-images-1.medium.com%2Fmax%2F3436%2F1%2AaXuwNK7ZRq1D3sszWvxeDQ.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%2Fcdn-images-1.medium.com%2Fmax%2F3436%2F1%2AaXuwNK7ZRq1D3sszWvxeDQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;JSON supports the following two data structures;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Collection of name/value pairs&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;An ordered list of values&lt;/strong&gt; − It includes arrays, lists, or sequences, etc.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A name/value pair consists of a field name (in double quotes), followed by a colon, followed by a value. So in the below example, the name is “firstName”, and the value is “John”.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; “firstName”: “John”&lt;/p&gt;

&lt;p&gt;You need to put text values between double-quotes. For numbers, boolean values, or null values, you &lt;strong&gt;do not&lt;/strong&gt; need double quotes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt; “age”: 24&lt;/p&gt;

&lt;p&gt;In JSON, values must be one of the following data types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;String&lt;/strong&gt; — Strings in JSON must be written in double quotes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Number&lt;/strong&gt; — Numbers in JSON must be an integer or a floating-point&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Object&lt;/strong&gt; (JSON object) — Values in JSON can be objects. However, objects as values in JSON must follow the same rules as JSON objects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Array&lt;/strong&gt; — Values in JSON can be arrays. Array values are provided between []&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Boolean&lt;/strong&gt; — Either true or false value&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Null&lt;/strong&gt; — Empty value or no value&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F5184%2F1%2AC8ycG_9wgvqGvq4Exa8gaA.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%2Fcdn-images-1.medium.com%2Fmax%2F5184%2F1%2AC8ycG_9wgvqGvq4Exa8gaA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example usage in Altogic Tester&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can send a POST request to the path “/posts” to trigger the “Create posts object” service which will create a posts object under posts model on the database with the input sent in JSON format:&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%2Fcdn-images-1.medium.com%2Fmax%2F5412%2F1%2AuewQcbvM2NfaVMhy4V62BA.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%2Fcdn-images-1.medium.com%2Fmax%2F5412%2F1%2AuewQcbvM2NfaVMhy4V62BA.png" alt="Altogic Tester"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading! Follow &lt;a href="https://medium.com/altogic" rel="noopener noreferrer"&gt;Altogic&lt;/a&gt; for more content like this and sample full-stack apps with full resources and tutorials.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>codenewbie</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 implement Magic Link Authentication with Next.js and Altogic</title>
      <dc:creator>Mert Yerekapan</dc:creator>
      <pubDate>Thu, 05 May 2022 05:16:57 +0000</pubDate>
      <link>https://dev.to/altogic/how-to-implement-magic-link-authentication-with-nextjs-and-altogic-4dc9</link>
      <guid>https://dev.to/altogic/how-to-implement-magic-link-authentication-with-nextjs-and-altogic-4dc9</guid>
      <description>&lt;h2&gt;
  
  
  How to implement Magic Link Authentication with Next.js and Altogic
&lt;/h2&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%2Fcdn-images-1.medium.com%2Fmax%2F2560%2F1%2Aq-FsWZkgNrdm9R5UYb0S6A.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%2Fcdn-images-1.medium.com%2Fmax%2F2560%2F1%2Aq-FsWZkgNrdm9R5UYb0S6A.png" alt="How to implement Magic Link Authentication with Next.js and Altogic"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This article will cover &lt;strong&gt;magic-link authentication&lt;/strong&gt; basics using Next.js and &lt;a href="https://altogic.com/" rel="noopener noreferrer"&gt;Altogic&lt;/a&gt;, a backend-as-a-service platform using its client library. This authentication method allows users to sign in to the application &lt;strong&gt;without&lt;/strong&gt; remembering their password.&lt;/p&gt;

&lt;p&gt;To reduce UX friction and avoid remembering multiple passwords, some small/medium and even large organizations are moving out from the password-based authentication flow to magic authentication, depending on their risk appetite.&lt;/p&gt;

&lt;p&gt;You can check out the &lt;a href="https://github.com/altogic/altogic/tree/main/examples/nextjs-magic-link-authentication" rel="noopener noreferrer"&gt;source code&lt;/a&gt; and &lt;a href="https://altogic-nextjs-magic-link-auth.vercel.app/" rel="noopener noreferrer"&gt;demo app&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Benefits
&lt;/h3&gt;

&lt;p&gt;With the magic link authentication method, the user does not have to remember another password or enter it to access their account. So we can clearly understand that magic link authentication highly simplifies the login burden for users and provides a better user experience.&lt;/p&gt;

&lt;h3&gt;
  
  
  Disadvantages
&lt;/h3&gt;

&lt;p&gt;For that authentication method, the primary condition is that the link needs to be safe and can not be able to manipulated from outside of the application. And the links should have to be used for just a few minutes and only once. So except for these conditions, a passwordless authentication seems safer than one with a password.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 If you know any other disadvantages that you discover or faced before, please write in the comments section, we would love to discuss and learn.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  How is the magic link authentication flow in Altogic?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Users who already have an account enter their email and click the “&lt;strong&gt;Send magic link&lt;/strong&gt;” button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An email with the magic link is sent to the specified email address by &lt;strong&gt;Altogic&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Users click on the link in the sent email.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Altogic redirects users to specified “&lt;strong&gt;Redirect URL&lt;/strong&gt;” with an access token in the query string parameter.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This access token is used to get a session token, and users are directed to their profile page.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;You can check out the video below to see a live demonstration of our app.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/k4UEqFp9jFk"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

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

&lt;p&gt;This project builds on top of the complete e-mail authentication app we created previously. You can follow the &lt;a href="https://medium.com/altogic/altogic-email-authentication-with-next-js-and-altogic-4c036c36ea8f" rel="noopener noreferrer"&gt;tutorial&lt;/a&gt; to build the same app or clone the project from &lt;a href="https://github.com/altogic/altogic/tree/main/examples/nextjs-email-authentication" rel="noopener noreferrer"&gt;here&lt;/a&gt; and continue with the rest of the tutorial.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let’s start coding!
&lt;/h2&gt;

&lt;p&gt;We already have the &lt;strong&gt;backend&lt;/strong&gt; and &lt;strong&gt;frontend&lt;/strong&gt; of the &lt;strong&gt;email authentication now&lt;/strong&gt;. We can start implementing the &lt;strong&gt;magic link functionality&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Set up the magic link page
&lt;/h3&gt;

&lt;p&gt;We need a page where we get the &lt;strong&gt;email&lt;/strong&gt; input from the user.&lt;/p&gt;

&lt;p&gt;Using the “altogic.auth.sendMagicLinkEmail(email)” we can send magic link mail to the specified email.&lt;/p&gt;

&lt;p&gt;Here is the source code of the &lt;code&gt;/auth/send-magic-link&lt;/code&gt; page:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
In the end, your screen should look like this:

&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%2Fcdn-images-1.medium.com%2Fmax%2F6912%2F1%2AITH5HiwNrDfsNqZQduhp2A%402x.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%2Fcdn-images-1.medium.com%2Fmax%2F6912%2F1%2AITH5HiwNrDfsNqZQduhp2A%402x.png" alt="Altogic send magic link screen"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Magic Link Email
&lt;/h3&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%2Fcdn-images-1.medium.com%2Fmax%2F3236%2F1%2AM45W1zKshZNXswHpAp5Rpw%402x.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%2Fcdn-images-1.medium.com%2Fmax%2F3236%2F1%2AM45W1zKshZNXswHpAp5Rpw%402x.png" alt="Default magic link email Altogic sends"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also change all of the message templates from the &lt;strong&gt;App settings → Authentication → Message templates&lt;/strong&gt; view of &lt;a href="https://designer.altogic.com/" rel="noopener noreferrer"&gt;&lt;strong&gt;Altogic Designer&lt;/strong&gt;&lt;/a&gt; and use &lt;strong&gt;any HTML template&lt;/strong&gt; you want.&lt;/p&gt;

&lt;p&gt;Here is how to do that:&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%2Fcdn-images-1.medium.com%2Fmax%2F7536%2F1%2AhwIXJvOSjdgBVsjHPo2xQg.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%2Fcdn-images-1.medium.com%2Fmax%2F7536%2F1%2AhwIXJvOSjdgBVsjHPo2xQg.png" alt="Change message templates in Altogic Designer"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that we sent the email, users need to click on the link to sign in.&lt;/p&gt;
&lt;h3&gt;
  
  
  Redirect URL route
&lt;/h3&gt;

&lt;p&gt;When users click on the link, &lt;strong&gt;Altogic&lt;/strong&gt; redirects to our specified Redirect URL, which is &lt;strong&gt;/auth-redirect&lt;/strong&gt; in this case.&lt;/p&gt;

&lt;p&gt;Here in &lt;strong&gt;getServerSideProps,&lt;/strong&gt; we check the query string parameters, and according to each action, we perform some actions. Here is an &lt;strong&gt;important&lt;/strong&gt; part!&lt;/p&gt;

&lt;p&gt;getAuthGrant() function either takes a session token as a parameter &lt;strong&gt;or&lt;/strong&gt; uses the one in the URL.&lt;/p&gt;

&lt;p&gt;Here, we run this code &lt;strong&gt;only on the server-side,&lt;/strong&gt; so we must &lt;strong&gt;give&lt;/strong&gt; the session token as the parameter.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  What happens if we click on the link again?
&lt;/h3&gt;

&lt;p&gt;Magic links are one-time links. If users click on the link a second time or after it expires, they get an error. This feature makes the magic link authentication method more secure.&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%2Fcdn-images-1.medium.com%2Fmax%2F3632%2F1%2An2vu4W04Wm2mFfVC5u9KOA.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%2Fcdn-images-1.medium.com%2Fmax%2F3632%2F1%2An2vu4W04Wm2mFfVC5u9KOA.png" alt="Magic link url when you use it again."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see from the &lt;strong&gt;URL&lt;/strong&gt;, the access token is already used or invalid.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 You can directly insert the error message from the link for convenience.&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;p&gt;This article added the magic link authentication method to our email authentication app using &lt;a href="https://nextjs.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;Next.js&lt;/strong&gt;&lt;/a&gt; and &lt;a href="https://clientapi.altogic.com/v1.2.2/modules.html" rel="noopener noreferrer"&gt;&lt;strong&gt;Altogic Client Library&lt;/strong&gt;&lt;/a&gt;. Thanks to &lt;a href="https://altogic.com/" rel="noopener noreferrer"&gt;&lt;strong&gt;Altogic&lt;/strong&gt;&lt;/a&gt;, we can build this 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/nextjs-magic-link-authentication" rel="noopener noreferrer"&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>webdev</category>
      <category>tutorial</category>
      <category>nextjs</category>
    </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>
    <item>
      <title>Complete Email Authentication with Next.js and Altogic</title>
      <dc:creator>Mert Yerekapan</dc:creator>
      <pubDate>Mon, 25 Apr 2022 13:05:36 +0000</pubDate>
      <link>https://dev.to/altogic/complete-email-authentication-with-nextjs-and-altogic-1h1i</link>
      <guid>https://dev.to/altogic/complete-email-authentication-with-nextjs-and-altogic-1h1i</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This article will cover email-based authentication basics using Next.js and &lt;a href="https://altogic.com" rel="noopener noreferrer"&gt;Altogic&lt;/a&gt;, a backend-as-a-service platform using its client library. This authentication method requires users to specify their email and passwords during sign-up. After signing up, users can log in to the application using their email and password. You can check the &lt;a href="https://github.com/altogic/altogic/tree/main/examples/nextjs-email-authentication" rel="noopener noreferrer"&gt;source code&lt;/a&gt; and &lt;a href="https://altogic-nextjs-email-auth.vercel.app/" rel="noopener noreferrer"&gt;demo app&lt;/a&gt;.&lt;br&gt;
By default, email verification is &lt;strong&gt;enabled&lt;/strong&gt; in your &lt;strong&gt;App settings → Authentication&lt;/strong&gt; view of &lt;strong&gt;Altogic Designer&lt;/strong&gt;. If you would like to change this, you can &lt;strong&gt;disable&lt;/strong&gt; “Confirm email addresses” in the &lt;strong&gt;Authentication&lt;/strong&gt; view of &lt;strong&gt;Altogic Designer&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  How is the email authentication flow in Altogic?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Users sign up with their email and password.&lt;/li&gt;
&lt;li&gt;A verification email is sent to the specified email address by Altogic.&lt;/li&gt;
&lt;li&gt;Users confirm their email by clicking on the link in the sent email.&lt;/li&gt;
&lt;li&gt;Altogic checks the token in clicked link and if valid changes the user’s email address to verified and returns an access token in the query string parameter of the redirect URL.&lt;/li&gt;
&lt;li&gt;This access token is used to get a session token and users are directed to their profile page.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Youtube Promo Video
&lt;/h3&gt;

&lt;p&gt;You can check out the video below to see a live demonstration of our app.&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/rlOTW_NuJzc"&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/" rel="noopener noreferrer"&gt;Designer&lt;/a&gt; easily. All you need to do is enter a name for your app.&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%2Fmm2a9cjtg0dcnb0dp83r.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%2Fmm2a9cjtg0dcnb0dp83r.png" alt="How to create an application in Altogic Designer."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We need &lt;code&gt;envUrl&lt;/code&gt; and &lt;code&gt;clientKey&lt;/code&gt; to access our environment via Altogic Client Library. &lt;code&gt;envUrl&lt;/code&gt; is specific to each environment, and Altogic initially creates one environment for you when you create your app. Here is how to get the &lt;code&gt;envUrl&lt;/code&gt; from environment details page.&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%2Fkmuaxdconjc0clvu6btv.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%2Fkmuaxdconjc0clvu6btv.png" alt="How to get ehe environment url in Altogic Designer."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can get the &lt;code&gt;clientKey&lt;/code&gt; 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;/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%2Fqa9n7d22i23josd8no5a.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%2Fqa9n7d22i23josd8no5a.png" alt="Here, Altogic already created one for us, but we can create more client library keys and configure the permissions for different keys."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Users model
&lt;/h3&gt;

&lt;p&gt;By default, &lt;strong&gt;Altogic&lt;/strong&gt; creates a user model for you. You can customize it by adding different fields. Some of them are pretty advanced and customized, which is very handy.&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 &lt;code&gt;npx&lt;/code&gt; 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/" rel="noopener noreferrer"&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;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-next-app@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Next.js will ask you to name the project. Name it whatever you want; I will use &lt;strong&gt;“altogic-email-authentication”&lt;/strong&gt; for this example. Move to the folder just created and &lt;strong&gt;install the Altogic Client Library&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;altogic-email-authentication
npm i altogic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Open the project in VSCode.&lt;br&gt;
Install &lt;strong&gt;tailwind CSS&lt;/strong&gt; and create &lt;code&gt;tailwind.config.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-D&lt;/span&gt; tailwindcss postcss autoprefixer
npx tailwindcss init &lt;span class="nt"&gt;-p&lt;/span&gt;
&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;/p&gt;


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



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


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


&lt;p&gt;Install &lt;strong&gt;Font Awesome&lt;/strong&gt; to use the icons.&lt;br&gt;
&lt;/p&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
npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save&lt;/span&gt; @fortawesome/free-solid-svg-icons
npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save&lt;/span&gt; @fortawesome/react-fontawesome
npm i @fortawesome/free-brands-svg-icons
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Install &lt;strong&gt;cookies-next&lt;/strong&gt; to set cookies for server-side rendering easily.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i cookies-next
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Install &lt;strong&gt;@headlesui/react&lt;/strong&gt; for styling.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i @headlessui/react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Update the &lt;code&gt;next.config.js&lt;/code&gt; file to allow the Next.js Image component to load images from Altogic’s storage. &lt;code&gt;"c1-na.altogic.com"&lt;/code&gt; value is retrieved from the &lt;code&gt;envUrl&lt;/code&gt; which starts with &lt;code&gt;c1-na.altogic.com&lt;/code&gt; in my case.&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.localfile&lt;/code&gt; 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" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;


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


&lt;p&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;br&gt;
Next, create a file to create the &lt;strong&gt;Altogic Client Library&lt;/strong&gt; instance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;helpers
&lt;span class="nb"&gt;cd &lt;/span&gt;helpers
&lt;span class="nb"&gt;touch &lt;/span&gt;client.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This creates a &lt;code&gt;client.js&lt;/code&gt; 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;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Here, you need to enter the &lt;code&gt;envUrl&lt;/code&gt; and &lt;code&gt;clientKey&lt;/code&gt;. Optionally you can paste &lt;code&gt;signInRedirect&lt;/code&gt; 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 &lt;code&gt;signInRedirect&lt;/code&gt; route.&lt;/p&gt;

&lt;h3&gt;
  
  
  Building our components
&lt;/h3&gt;

&lt;p&gt;The next step is to create the components we’ll need for our application. You can also clone our example repository and use the components right away.&lt;br&gt;
First, create a components folder with the &lt;code&gt;mkdir components&lt;/code&gt; command. Let me walk you through the components we use for our app.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;Sign-in.js&lt;/code&gt; and &lt;code&gt;Sign-up.js&lt;/code&gt; file in &lt;code&gt;auth&lt;/code&gt; directory. Those are the form components we use to sign-up and sign in our users.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;EmailConfirmResend.js&lt;/code&gt; and &lt;code&gt;PasswordReset.js&lt;/code&gt; file in &lt;code&gt;auth-redirect&lt;/code&gt; directory. Those are the components we will show our users when redirected to the &lt;strong&gt;our-domain.com/auth-redirect&lt;/strong&gt; route.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;AltogicBadge.js&lt;/code&gt;, &lt;code&gt;Header.js&lt;/code&gt; and &lt;code&gt;Layout.js&lt;/code&gt; file in &lt;code&gt;layout&lt;/code&gt; directory. Those are the components we use for our layout throughout the app.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SessionListItem.js&lt;/code&gt; ,&lt;code&gt;SessionList.js&lt;/code&gt; , &lt;code&gt;ProfilePhoto.js&lt;/code&gt;, &lt;code&gt;NameSection.js&lt;/code&gt; , &lt;code&gt;ChangePassword.js&lt;/code&gt; and &lt;code&gt;ChangeEmail.js&lt;/code&gt; file in &lt;code&gt;profile&lt;/code&gt; directory. Those are the components we use on the profile page.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Button.js&lt;/code&gt; , &lt;code&gt;Notification.js&lt;/code&gt; and &lt;code&gt;ErrorMessage.js&lt;/code&gt; file in &lt;code&gt;ui&lt;/code&gt; directory. Those are the components we use many times to build our UI.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the end, your components folder should look like this:&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%2Fzxgxdvo3eb4skqetafam.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%2Fzxgxdvo3eb4skqetafam.png" alt="Components folder"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Let’s start coding!
&lt;/h2&gt;

&lt;p&gt;We have the backend and frontend setup ready. We can start integrating them now.&lt;/p&gt;
&lt;h3&gt;
  
  
  Some UI components we use often
&lt;/h3&gt;

&lt;p&gt;It is best to separate the logic of some of the components we use frequently and put them into a different folder to reuse.&lt;br&gt;
&lt;strong&gt;Button:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Error:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Sign up functionality with Altogic
&lt;/h3&gt;

&lt;p&gt;Altogic Client Library has a built-in function for creating new users with an email and password. You can check about it more &lt;a href="https://clientapi.altogic.com/v1.2.2/classes/AuthManager.html#signUpWithEmail" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;br&gt;
&lt;strong&gt;altogic&lt;/strong&gt;.auth.&lt;strong&gt;signUpWithEmail&lt;/strong&gt; takes three inputs:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;email (mandatory)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;password (mandatory)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;name (optional)&lt;/strong&gt;
The code snippet handles the form input using the &lt;strong&gt;signUpWithEmail&lt;/strong&gt; function.&lt;/li&gt;
&lt;/ol&gt;


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


&lt;p&gt;Our sign-up screen should look like this:&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%2Fpgalq8kdm78fwtjgc5fb.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%2Fpgalq8kdm78fwtjgc5fb.png" alt="Sign-up Screen"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This function will create a user object in your database with the provided &lt;strong&gt;email&lt;/strong&gt;, &lt;strong&gt;password&lt;/strong&gt;, and optionally &lt;strong&gt;name&lt;/strong&gt; field. Altogic will send an email to the user’s email address.&lt;/p&gt;

&lt;h3&gt;
  
  
  Redirect URL route
&lt;/h3&gt;

&lt;p&gt;In &lt;strong&gt;Altogic&lt;/strong&gt;, you can redirect your users to a predefined route for some actions.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When the user is successfully authenticated using an oAuth provider or a magic link, they will be redirected here.&lt;/li&gt;
&lt;li&gt;When the email confirmation link is clicked, they are redirected to this route.&lt;/li&gt;
&lt;li&gt;When a user changes their email, if the email confirmation setting of the app is enabled, an email is sent to them. After the user clicks it, they will be redirected to this route.&lt;/li&gt;
&lt;li&gt;When a user recovers their password, they are redirected to this route.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can check and edit this route from &lt;a href="https://designer.altogic.com/" rel="noopener noreferrer"&gt;Designer&lt;/a&gt; like below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpso888xvd0vx2fyvgpig.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%2Fpso888xvd0vx2fyvgpig.png" alt="Change REDIRECT URL"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here in &lt;strong&gt;getServerSideProps&lt;/strong&gt;, we check the query string parameters and according to each action, we perform some actions. Here is an &lt;strong&gt;important&lt;/strong&gt; part!&lt;/p&gt;

&lt;p&gt;&lt;code&gt;getAuthGrant()&lt;/code&gt; function either takes a session token as a parameter &lt;strong&gt;or&lt;/strong&gt; uses the one in the URL.&lt;/p&gt;

&lt;p&gt;In the example below, &lt;strong&gt;Altogic&lt;/strong&gt; sent the user an &lt;strong&gt;email confirmation&lt;/strong&gt; mail. When clicked, it redirects to our specified &lt;strong&gt;Redirect URL&lt;/strong&gt;, which is &lt;strong&gt;auth-redirect&lt;/strong&gt;. &lt;br&gt;
There are three query parameters:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;status=200&lt;/strong&gt; indicates that Altogic managed to send me a valid token for my operation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;access_token&lt;/strong&gt; gives us the token value I am going to use.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;action=email-confirm&lt;/strong&gt; indicates for which action I am going to use this token. In this case, it is confirming my email.&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%2Fcbvze4hqlmpi4ktowi18.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%2Fcbvze4hqlmpi4ktowi18.png" alt="Access token as query string parameter"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, we run this code &lt;strong&gt;only on the server-side&lt;/strong&gt;, so we must &lt;strong&gt;give&lt;/strong&gt; the session token as the parameter.&lt;/p&gt;


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


&lt;h3&gt;
  
  
  Sign in functionality with Altogic
&lt;/h3&gt;

&lt;p&gt;Altogic Client Library also has a built-in function for signing in users. You can check about it more &lt;a href="https://clientapi.altogic.com/v1.2.2/classes/AuthManager.html#signInWithEmail" rel="noopener noreferrer"&gt;here&lt;/a&gt;. The code snippet handles the form input using the &lt;strong&gt;signInWithEmail&lt;/strong&gt; function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;altogic&lt;/strong&gt;.auth.&lt;strong&gt;signInWithEmail&lt;/strong&gt; takes two inputs:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;email&lt;/strong&gt; (&lt;strong&gt;mandatory&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;password&lt;/strong&gt; (&lt;strong&gt;mandatory&lt;/strong&gt;)&lt;/li&gt;
&lt;/ol&gt;


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


&lt;p&gt;As you can see in the code above, we are sending a &lt;strong&gt;POST&lt;/strong&gt; request to &lt;strong&gt;/api/login&lt;/strong&gt; route. We are doing this to set the cookie for &lt;strong&gt;server-side rendering&lt;/strong&gt; (SSR). If you are not going to use &lt;strong&gt;SSR&lt;/strong&gt;, you can delete these lines.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why do we need cookies for SSR?
&lt;/h3&gt;

&lt;p&gt;One of the key features of Next.js is &lt;strong&gt;server-side rendering&lt;/strong&gt;. Meaning that some of the code will run &lt;strong&gt;only&lt;/strong&gt; on the server and &lt;strong&gt;not&lt;/strong&gt; on the client side. But session and user information is stored on the &lt;strong&gt;client-side&lt;/strong&gt;. How do we understand if &lt;strong&gt;we have a user authenticated&lt;/strong&gt; when a request is made to the server? For this purpose, we need to &lt;strong&gt;set a cookie&lt;/strong&gt; on the server-side when we sign in and &lt;strong&gt;delete it&lt;/strong&gt; when we sign out. This way, we can check if the user is authenticated on the server-side and then perform the actions we want.&lt;br&gt;
Here is the code you need to add to your &lt;strong&gt;api/login&lt;/strong&gt; folder:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
On any page, we can check if there is a user signed in or not. This part is needed both for route protection and fetching data special to the user with SSR.

&lt;p&gt;Our sign-in screen should look like this:&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%2Ftall7kmugko5ur2bysdc.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%2Ftall7kmugko5ur2bysdc.png" alt="Sign-in Page"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  How to check if there is a user authenticated via SSR?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;getServerSideProps&lt;/strong&gt; function runs every time the user makes a request. It runs &lt;strong&gt;only&lt;/strong&gt; on the server, and its content is not exposed to the client. We check if a user is authenticated and redirect them to their profile or sign-in page accordingly.&lt;/p&gt;


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


&lt;h3&gt;
  
  
  Signout users
&lt;/h3&gt;

&lt;p&gt;Here is the page you can redirect your users to log them out. It simply invalidates the session, clears the context, and sends a &lt;strong&gt;POST&lt;/strong&gt; request to &lt;strong&gt;our-domain/api/logout&lt;/strong&gt; to clear the cookies.&lt;/p&gt;


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


&lt;p&gt;When we sign out, we need to &lt;strong&gt;delete&lt;/strong&gt; the cookie we set on the &lt;strong&gt;server-side&lt;/strong&gt; because the token value in the cookie is &lt;strong&gt;no longer valid&lt;/strong&gt;.&lt;br&gt;
Here is the code you need to add to your &lt;strong&gt;api/logout&lt;/strong&gt; file:&lt;/p&gt;


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


&lt;h3&gt;
  
  
  Storing user information in context
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;UserContext&lt;/code&gt; creates a context and sets the user and session property null by default. To learn more about context and how to effectively use them, read &lt;a href="https://reactjs.org/docs/context.html" rel="noopener noreferrer"&gt;React’s documentation on context&lt;/a&gt;.&lt;/p&gt;


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


&lt;h3&gt;
  
  
  More features
&lt;/h3&gt;

&lt;p&gt;Our example application covers more features like uploading a profile picture, managing sessions, password recovery, password change, and email change. You can check all of them in the repository. Here, I just want to show you how easily you can implement them with client library functions.&lt;/p&gt;


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


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

&lt;p&gt;In this article, we built a simple yet capable email authentication app using &lt;strong&gt;Next.js&lt;/strong&gt; and &lt;strong&gt;Altogic Client Library&lt;/strong&gt;. Generally, building authentication is one of the most challenging parts of app development. Thanks to &lt;strong&gt;Altogic&lt;/strong&gt;, we can build this 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-email-authentication" rel="noopener noreferrer"&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>nextjs</category>
      <category>altogic</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
