<?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: Nico Montiel</title>
    <description>The latest articles on DEV Community by Nico Montiel (@nicolasmontielf).</description>
    <link>https://dev.to/nicolasmontielf</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F489991%2F8b0cdd76-a1c5-47c8-bbb4-2d1fa6ddf4d3.jpg</url>
      <title>DEV Community: Nico Montiel</title>
      <link>https://dev.to/nicolasmontielf</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nicolasmontielf"/>
    <language>en</language>
    <item>
      <title>Stop Over-Engineering: Just deploy your project 🛸</title>
      <dc:creator>Nico Montiel</dc:creator>
      <pubDate>Mon, 23 Feb 2026 14:00:00 +0000</pubDate>
      <link>https://dev.to/nicolasmontielf/stop-over-engineering-why-i-moved-my-laravel-app-from-aws-to-a-simple-vps-33mc</link>
      <guid>https://dev.to/nicolasmontielf/stop-over-engineering-why-i-moved-my-laravel-app-from-aws-to-a-simple-vps-33mc</guid>
      <description>&lt;p&gt;We’ve all been there. You are building a new project, and you want to do everything "the right way." You follow the tutorials, you look at the enterprise-grade architectures, and you end up building a monster before you even have your first 20 users.&lt;/p&gt;

&lt;p&gt;I made that mistake...&lt;/p&gt;

&lt;h3&gt;
  
  
  The "Golden" Architecture (The Mistake)
&lt;/h3&gt;

&lt;p&gt;When I first launched my Laravel e-commerce app, I went all-in on AWS. I wanted reliability, low latency for LATAM, and scalability. My stack looked like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Compute: EC2 (t3.large)&lt;/li&gt;
&lt;li&gt;Database: AWS RDS (Managed MySQL)&lt;/li&gt;
&lt;li&gt;Cache: Redis via Upstash&lt;/li&gt;
&lt;li&gt;Storage: S3 for images&lt;/li&gt;
&lt;li&gt;Region: São Paulo (sa-east-1) to keep it close to home.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On paper, this was the "correct" way to deploy a professional web app. In reality? It was a financial drain. I was paying for an infrastructure that could handle thousands of concurrent users while I was barely seeing 10 visits a day.&lt;/p&gt;

&lt;p&gt;The AWS "best practices" are great for companies with VC funding or massive traffic. For an indie dev or a startup in its early stages, over-engineering is a silent killer.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Switch: Back to Basics
&lt;/h3&gt;

&lt;p&gt;I decided to stop following the hype and start following my wallet. I moved everything—the App, MySQL, and Redis—to a single server on Hetzner.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cost: 3x cheaper than the AWS setup.&lt;/li&gt;
&lt;li&gt;Performance: Virtually the same for the end-user.&lt;/li&gt;
&lt;li&gt;Maintenance: Significantly easier. One server, one config.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Before:&lt;br&gt;
&lt;a href="https://media2.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%2Fqu3n6kh7247bjwkdgysu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fqu3n6kh7247bjwkdgysu.png" alt=" " width="800" height="208"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Ft5dvwhvkwxu81tsgikig.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Ft5dvwhvkwxu81tsgikig.png" alt=" " width="634" height="226"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  "But it won't scale!"
&lt;/h3&gt;

&lt;p&gt;I can already hear the comments: "What about the single point of failure?" "What about the bottleneck?" "That won't scale to a million users!"&lt;/p&gt;

&lt;p&gt;You are right. It won't. And that’s perfectly fine.&lt;/p&gt;

&lt;p&gt;Getting from 10 users to 5,000 daily active users is a monumental task. Most projects never reach that point. If you are lucky enough to hit those numbers, that is when you worry about scaling. Until then, your only priority should be staying alive and keeping your costs low.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Takeaway: Just Ship It (Simply)
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Don't let infrastructure be the reason you quit.&lt;/li&gt;
&lt;li&gt;Keep it simple.&lt;/li&gt;
&lt;li&gt;Deploy on a cheap VPS.&lt;/li&gt;
&lt;li&gt;Focus on your code and your users.&lt;/li&gt;
&lt;li&gt;Upgrade only when the demand forces you to.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Scaling is a "good" problem to have. Don't try to solve "good" problems before you even have customers.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>software</category>
      <category>infrastructure</category>
    </item>
    <item>
      <title>I’m from a country you’ve probably never heard of: How I got a remote job in the US 🙌🏻</title>
      <dc:creator>Nico Montiel</dc:creator>
      <pubDate>Sun, 22 Feb 2026 13:01:00 +0000</pubDate>
      <link>https://dev.to/nicolasmontielf/im-from-a-country-youve-probably-never-heard-of-how-i-got-a-remote-job-in-the-us-2o5f</link>
      <guid>https://dev.to/nicolasmontielf/im-from-a-country-youve-probably-never-heard-of-how-i-got-a-remote-job-in-the-us-2o5f</guid>
      <description>&lt;p&gt;Hello! My name is Nico. I'm a software engineer from &lt;a href="https://en.wikipedia.org/wiki/Paraguay" rel="noopener noreferrer"&gt;Paraguay&lt;/a&gt;, and since 2021, I've been working fully remote for companies in LATAM, Europe, and the US.&lt;/p&gt;

&lt;p&gt;Why am I writing this? If you are from a country like mine and want to start working globally, I want to share some quick advice on how to make it happen!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;⚠️ Disclaimer: This is based on my personal experience.
There is no magic formula; read this and draw your own conclusions.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Learn English
&lt;/h3&gt;

&lt;p&gt;First things first: this is your &lt;strong&gt;number one priority&lt;/strong&gt;. If you're a developer and don't know English, stop focusing on React or Rust for a moment. Learn English first. While AI can help you write emails or documentation, real-time communication in meetings is what gets you (and keeps you) the job.&lt;/p&gt;

&lt;h3&gt;
  
  
  A bit of experience
&lt;/h3&gt;

&lt;p&gt;I recommend having at least a few years of experience before applying to international companies. Why? There is a massive market for junior developers, but companies often prefer local talent for entry-level roles to simplify onboarding and legalities.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prepare an AI-friendly resume
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Keep it simple&lt;/strong&gt;. Avoid fancy colors or complex layouts. Most companies use ATS &lt;em&gt;(Applicant Tracking Systems)&lt;/em&gt; —often powered by AI— to screen resumes. If an algorithm can’t parse your data, a human will never see it. Make it readable for both machines and tired recruiters who have already seen 100 resumes before yours.&lt;/p&gt;

&lt;h3&gt;
  
  
  Logic over "LeetCode"
&lt;/h3&gt;

&lt;p&gt;Is learning algorithms still necessary? Yes, but &lt;strong&gt;with a twist&lt;/strong&gt;. In the AI era, writing the code is the easy part. However, you need to understand complexity (O(n) notation) and logic to verify if the code the AI generated is efficient or even correct. Practice basic algorithms to sharpen your mental models, not just to memorize solutions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Master the basics
&lt;/h3&gt;

&lt;p&gt;AI frequently "hallucinates" or provides outdated patterns. To debug effectively, you must know the fundamentals. If you use React, master JavaScript (scopes, event loops, closures). If you use Laravel, master PHP.&lt;br&gt;
Scientific evidence in software engineering suggests that strong foundational knowledge is the best predictor of a developer's ability to adapt to new tools, including AI.&lt;/p&gt;

&lt;h3&gt;
  
  
  The numbers game
&lt;/h3&gt;

&lt;p&gt;Applying for jobs is a marathon. You might send 100 resumes and get 99 rejections. That’s normal. &lt;strong&gt;You only need one "yes" to change your career&lt;/strong&gt;. It can be frustrating, but the reward of a remote international career is worth the effort.&lt;/p&gt;

&lt;p&gt;Thanks for reading! Working remotely changed my life, and I hope it does the same for you 💪🏻&lt;/p&gt;

</description>
      <category>career</category>
      <category>remote</category>
      <category>remotejob</category>
      <category>webdev</category>
    </item>
    <item>
      <title>💬 Integrating Twilio into your project: Part 3 - Handling Webhooks and Sending Messages with Laravel and Express</title>
      <dc:creator>Nico Montiel</dc:creator>
      <pubDate>Wed, 28 May 2025 17:00:00 +0000</pubDate>
      <link>https://dev.to/nicolasmontielf/integrating-twilio-into-your-project-part-3-handling-webhooks-and-sending-messages-with-242l</link>
      <guid>https://dev.to/nicolasmontielf/integrating-twilio-into-your-project-part-3-handling-webhooks-and-sending-messages-with-242l</guid>
      <description>&lt;p&gt;In this part, we'll:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a simple service to send WhatsApp messages.&lt;/li&gt;
&lt;li&gt;Handle incoming WhatsApp messages by replying automatically.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🐘 1. Twilio Service and Webhook in Laravel
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Install Twilio SDK
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require twilio/sdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Create a simple Twilio service
&lt;/h3&gt;

&lt;p&gt;Create a file at &lt;code&gt;app/Services/TwilioService.php&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;App\Services&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Twilio\Rest\Client&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;TwilioService&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$twilio&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;twilio&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;env&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'TWILIO_ACCOUNT_SID'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nf"&gt;env&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'TWILIO_AUTH_TOKEN'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;sendMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$to&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;twilio&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="s2"&gt;"whatsapp:"&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$to&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;[&lt;/span&gt;
                &lt;span class="s1"&gt;'from'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"whatsapp:"&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nf"&gt;env&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'TWILIO_WHATSAPP_FROM'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                &lt;span class="s1"&gt;'body'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$message&lt;/span&gt;
            &lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Set up the webhook route and use the service
&lt;/h3&gt;

&lt;p&gt;Add this to your &lt;code&gt;routes/web.php&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Illuminate\Http\Request&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;App\Services\TwilioService&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/webhook'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Request&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$phone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'From'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nv"&gt;$incomingMessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Body'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nv"&gt;$twilio&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TwilioService&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nv"&gt;$twilio&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;sendMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$phone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Hey 👋, thanks for your message: &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="nv"&gt;$incomingMessage&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;response&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;'status'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'message sent'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Now when Twilio sends a message, your webhook will automatically reply using the service!&lt;/p&gt;




&lt;h2&gt;
  
  
  🟰 2. Twilio Service and Webhook in Express
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Install Twilio SDK
&lt;/h3&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;twilio express
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Create a simple Twilio service
&lt;/h3&gt;

&lt;p&gt;Create a file &lt;code&gt;twilioService.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Twilio&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;twilio&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Twilio&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;TWILIO_ACCOUNT_SID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;TWILIO_AUTH_TOKEN&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sendMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;from&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;whatsapp:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;TWILIO_WHATSAPP_FROM&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;whatsapp:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;sendMessage&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Set up the webhook route and use the service
&lt;/h3&gt;

&lt;p&gt;In your &lt;code&gt;server.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;sendMessage&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./twilioService&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;express&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;urlencoded&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;extended&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}));&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/webhook&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;phone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;From&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;incomingMessage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Body&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;sendMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;phone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`Hey 👋, thanks for your message: "&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;incomingMessage&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;message sent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Server running on port 3000&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Now your Express app will automatically reply when a message is received!&lt;/p&gt;




&lt;h2&gt;
  
  
  🌎 3. Exposing your Local Server with ngrok
&lt;/h2&gt;

&lt;p&gt;Since Twilio needs a &lt;strong&gt;public URL&lt;/strong&gt;, you'll need to expose your localhost using &lt;a href="https://ngrok.com/" rel="noopener noreferrer"&gt;ngrok&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Install ngrok
&lt;/h3&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;-g&lt;/span&gt; ngrok
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Start ngrok
&lt;/h3&gt;

&lt;p&gt;For Laravel (port 8000):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ngrok http 8000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Express (port 3000):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ngrok http 3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;ngrok will give you a public URL like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;https://random-ngrok-url.ngrok.io
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Set this URL in your &lt;strong&gt;Twilio Sandbox Settings&lt;/strong&gt; under "WHEN A MESSAGE COMES IN", adding &lt;code&gt;/webhook&lt;/code&gt; at the end.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://random-ngrok-url.ngrok.io/webhook
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you need more details using ngrok, you can check &lt;a href="https://dev.to/drsimplegraffiti/ngrok-expose-a-local-web-server-to-the-internet-4m67"&gt;this post&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  🛠️ What's Next?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Customize replies based on user input.&lt;/li&gt;
&lt;li&gt;Validate incoming requests from Twilio.&lt;/li&gt;
&lt;li&gt;Move from Sandbox to Production environment.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Good luck! 🚀&lt;/p&gt;

</description>
      <category>twilio</category>
      <category>programming</category>
      <category>node</category>
      <category>php</category>
    </item>
    <item>
      <title>📲 Integrating Twilio into your project: Part 2 - Setting up the Sandbox and Handling Webhooks</title>
      <dc:creator>Nico Montiel</dc:creator>
      <pubDate>Tue, 27 May 2025 17:00:00 +0000</pubDate>
      <link>https://dev.to/nicolasmontielf/integrating-twilio-into-your-project-part-2-setting-up-the-sandbox-and-handling-webhooks-j02</link>
      <guid>https://dev.to/nicolasmontielf/integrating-twilio-into-your-project-part-2-setting-up-the-sandbox-and-handling-webhooks-j02</guid>
      <description>&lt;h2&gt;
  
  
  1. Joining the Twilio Sandbox
&lt;/h2&gt;

&lt;p&gt;Before you can start receiving messages via Webhook, you need to join the WhatsApp Sandbox.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here's how:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In your Twilio Console, navigate to &lt;em&gt;Messaging &amp;gt; Try it Out &amp;gt; Send a WhatsApp message.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;You’ll see a Sandbox section.&lt;/li&gt;
&lt;li&gt;Send the provided code (something like "join magic-pizza") to the given WhatsApp number.
In my case, it was "join control-type".&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;✅ Done! Your phone is now linked to the Sandbox.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F8lkml9gc81rurce7vrwu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F8lkml9gc81rurce7vrwu.png" alt="Image of Twilio sandbox" width="800" height="504"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt;&lt;br&gt;
Only registered numbers can send and receive messages in the Sandbox. If you change phones or SIMs, you’ll need to register again.&lt;/p&gt;
&lt;h2&gt;
  
  
  2. Setting up your Webhook URL
&lt;/h2&gt;

&lt;p&gt;Next, you’ll tell Twilio where to send incoming messages.&lt;/p&gt;

&lt;p&gt;In the Sandbox settings, set your Webhook URL for incoming messages (e.g., &lt;a href="https://yourdomain.com/webhook" rel="noopener noreferrer"&gt;https://yourdomain.com/webhook&lt;/a&gt;).&lt;br&gt;&lt;br&gt;
You can do this on the same page, under the "Sandbox Settings" tab.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F8w5qylges1zknw09e5z8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F8w5qylges1zknw09e5z8.png" alt="Image of Twilio sandbox" width="800" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Make sure your server can accept &lt;code&gt;POST&lt;/code&gt; requests from Twilio.&lt;/p&gt;

&lt;p&gt;Now, every time that phone number receives a WhatsApp message, Twilio will send the message to your webhook so you can handle the incoming message.&lt;/p&gt;

&lt;p&gt;Twilio will send a payload like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"SmsMessageSid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"SMc8df133659ef2ca4251da5b1ac5453cdg"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"NumMedia"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"ProfileName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"John Smith"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"MessageType"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"SmsSid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"SMc8df133659ef2ca4251da5b1ac5453cdg"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"WaId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"+157822787582693"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"SmsStatus"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"received"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Body"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"The body of the message that you are receiving"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"To"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"whatsapp:+157822787584443"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"NumSegments"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"ReferralNumMedia"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"MessageSid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"SMc8df133659ef2ca4251da5b1ac5453cdg"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"AccountSid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"youraccountId"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"From"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"whatsapp:+157822787582693"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"ApiVersion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2010-04-01"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll code a real webhook handler in the next part 😉&lt;/p&gt;

</description>
      <category>twilio</category>
      <category>programming</category>
      <category>node</category>
      <category>php</category>
    </item>
    <item>
      <title>📞 Integrating Twilio into your project: Part 1 - Creating your account</title>
      <dc:creator>Nico Montiel</dc:creator>
      <pubDate>Mon, 26 May 2025 17:00:00 +0000</pubDate>
      <link>https://dev.to/nicolasmontielf/integrating-twilio-into-your-project-part-1-creating-your-account-1oof</link>
      <guid>https://dev.to/nicolasmontielf/integrating-twilio-into-your-project-part-1-creating-your-account-1oof</guid>
      <description>&lt;h2&gt;
  
  
  1. Creating a Twilio account
&lt;/h2&gt;

&lt;p&gt;First things first: let's create an account at &lt;a href="https://www.twilio.com/try-twilio" rel="noopener noreferrer"&gt;Twilio&lt;/a&gt;.&lt;br&gt;
It's super quick:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to the website.&lt;/li&gt;
&lt;li&gt;Sign up (you can use GitHub, Google, or just a regular email).&lt;/li&gt;
&lt;li&gt;Once you're in, verify your real phone number (this is mandatory to test stuff).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Important:&lt;br&gt;
Twilio gives you free trial credits. 🙌 You'll be able to send a few messages for free.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Getting your credentials
&lt;/h2&gt;

&lt;p&gt;Inside your Twilio Console, grab your:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Account SID&lt;/li&gt;
&lt;li&gt;Auth Token&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 You’ll find them right on your main dashboard.&lt;br&gt;
&lt;a href="https://media2.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%2Fy752p7zh1py3595ziezj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fy752p7zh1py3595ziezj.png" alt="Image of Twilio main dashboard" width="800" height="503"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First part it's done, super easy!&lt;/p&gt;

</description>
      <category>twilio</category>
      <category>programming</category>
      <category>node</category>
      <category>php</category>
    </item>
    <item>
      <title>Add typing to your Javascript code (without Typescript, kinda) ✍🏼</title>
      <dc:creator>Nico Montiel</dc:creator>
      <pubDate>Tue, 20 Feb 2024 23:59:21 +0000</pubDate>
      <link>https://dev.to/nicolasmontielf/add-typing-to-your-javascript-code-without-typescript-kinda-3aph</link>
      <guid>https://dev.to/nicolasmontielf/add-typing-to-your-javascript-code-without-typescript-kinda-3aph</guid>
      <description>&lt;p&gt;Hey there.&lt;/p&gt;

&lt;p&gt;I recently started working on a full Javascript project. And after years of working with Typescript, it was strange to work in an environment where no one is telling me "Hey, that property is not there, man".&lt;/p&gt;

&lt;p&gt;So I start researching about the better way to do this, without implementing Typescript, because migrating to Typescript is a big job that most of the company doesn't find worthwhile in older projects.&lt;/p&gt;

&lt;p&gt;The best way to do this, of course, is with &lt;a href="https://jsdoc.app/" rel="noopener noreferrer"&gt;JSDoc&lt;/a&gt;. But something I always found awkward about jsdoc is defining the object types in the same file.&lt;br&gt;
So, after a lot of reading, I found a way to combine JSDoc with &lt;a href="https://www.typescriptlang.org/docs/handbook/2/type-declarations.html" rel="noopener noreferrer"&gt;declaration type&lt;/a&gt; files from Typescript. Let me give you an example:&lt;/p&gt;

&lt;p&gt;This is your type declaration file, something like &lt;code&gt;types.d.ts&lt;/code&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Product&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;sku&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
    &lt;span class="nx"&gt;available&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;
    &lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;double&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This is your javascript file, maybe your &lt;code&gt;index.js&lt;/code&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cm"&gt;/** @type {import('./types.d.ts').Product} */&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;product&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;sku&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;123&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;My product&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;available&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;12.00&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;So here, if you put a wrong value in the object &lt;code&gt;product&lt;/code&gt;, you editor is going to let you know:&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%2Fn91micsst3q8t3m0nde2.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%2Fn91micsst3q8t3m0nde2.png" alt="Image from vscode showing an error because of the type"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's all, I hope it can be helpful for you 🥳&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>jsdoc</category>
      <category>typing</category>
    </item>
    <item>
      <title>A good code snippet for your posts 💻</title>
      <dc:creator>Nico Montiel</dc:creator>
      <pubDate>Sun, 18 Feb 2024 20:06:50 +0000</pubDate>
      <link>https://dev.to/nicolasmontielf/a-good-code-snippet-for-your-posts-dhm</link>
      <guid>https://dev.to/nicolasmontielf/a-good-code-snippet-for-your-posts-dhm</guid>
      <description>&lt;p&gt;I just want to share with you a cool tool that I have been using a lot lately called "Carbon". It allows you to create and share beautiful images of your source code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fvc0mcsth36b1lh552m7p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fvc0mcsth36b1lh552m7p.png" alt="Image of Carbon landing page" width="800" height="506"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is pretty useful if you want to share some code in Slack, LinkedIn, or even in a post here.&lt;br&gt;
It is super easy to use and super easy to customize.&lt;/p&gt;

&lt;p&gt;Of course, you can write your code here and it looks good, right?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// taking kilometers input from the user&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;kilometers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Enter value in kilometers: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// conversion factor&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;factor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.621371&lt;/span&gt;

&lt;span class="c1"&gt;// calculate miles&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;miles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;kilometers&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;factor&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;kilometers&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; kilometers is equal to &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;miles&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; miles.`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But c'mon, this looks clean&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F8o5spq9i2a9wu1p1r0dj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F8o5spq9i2a9wu1p1r0dj.png" alt="Code snippet from Carbon" width="800" height="463"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's all, I hope it can be helpful for you 🥳&lt;/p&gt;

</description>
      <category>snippet</category>
      <category>developer</category>
      <category>carbon</category>
    </item>
    <item>
      <title>Write better PR's with this template 📄</title>
      <dc:creator>Nico Montiel</dc:creator>
      <pubDate>Sun, 18 Feb 2024 03:19:16 +0000</pubDate>
      <link>https://dev.to/nicolasmontielf/writing-a-good-pull-request-with-template-46pm</link>
      <guid>https://dev.to/nicolasmontielf/writing-a-good-pull-request-with-template-46pm</guid>
      <description>&lt;p&gt;Hey there!&lt;/p&gt;

&lt;p&gt;So, recently I started in a new company where the process of reviewing code is not a critical part of the workflow, so I am developing a template for our pull request, in an atempt to improve our codebase and the process of reviewing a new change.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why did I do this? Was it really necessary?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;YES&lt;/strong&gt;. I think a pull request should be a kind of documentation where you explain the context of your changes to your colleagues, not explaining the code, but explaining the business logic behind this change, why are you doing this work?&lt;/p&gt;

&lt;p&gt;So I created a template for this, and set it as the default template every time you want to create a new PR.&lt;/p&gt;

&lt;h3&gt;
  
  
  Here is the template:
&lt;/h3&gt;


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


&lt;h3&gt;
  
  
  Add the template as default in Github
&lt;/h3&gt;

&lt;p&gt;And if you use Github, putting this as a PR template is super easy, you just need to create a file called &lt;code&gt;pull_request_template.md&lt;/code&gt; and put it in the root of your project, or inside the &lt;code&gt;.github&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;You can see this with more details here: &lt;a href="https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/creating-a-pull-request-template-for-your-repository"&gt;https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/creating-a-pull-request-template-for-your-repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's all, I hope it can be helpful for you 🥳&lt;/p&gt;

</description>
      <category>programming</category>
      <category>git</category>
      <category>pullrequest</category>
      <category>engineering</category>
    </item>
    <item>
      <title>Add role and permission on your Laravel project 🔐</title>
      <dc:creator>Nico Montiel</dc:creator>
      <pubDate>Tue, 04 Apr 2023 18:39:10 +0000</pubDate>
      <link>https://dev.to/nicolasmontielf/add-permissions-and-roles-to-your-laravel-project-2hhl</link>
      <guid>https://dev.to/nicolasmontielf/add-permissions-and-roles-to-your-laravel-project-2hhl</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Authorization is a critical aspect of any application, as it ensures that users only have access to the resources they are allowed to see or modify. Laravel provides built-in features to make it easier to implement authorization in your application. In this post, we will learn how to implement authorization in Laravel without using any external libraries.&lt;/p&gt;

&lt;h1&gt;
  
  
  Why is Authorization important and how Laravel helps with that
&lt;/h1&gt;

&lt;p&gt;Authorization is important for security reasons, as it ensures that users only have access to the parts of the application they are authorized to use. Laravel makes it easy to implement authorization through its built-in middleware, which can be used to protect routes and actions.&lt;/p&gt;

&lt;h1&gt;
  
  
  Creating the models
&lt;/h1&gt;

&lt;p&gt;To keep this post from being too long, let's assume we've already created the migrations. If not, you can see the fillable property on the models and assume the table shape.&lt;br&gt;
To implement authorization in Laravel without using external libraries, we need to create our own models for permissions, roles, and users. We can create the following models:&lt;/p&gt;

&lt;h3&gt;
  
  
  Permissions model
&lt;/h3&gt;

&lt;p&gt;This model only contains the relationship with the roles. Here is a small description of the fields:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;name:&lt;/strong&gt; The permission name -&amp;gt; post.create&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;display_name:&lt;/strong&gt; A formated name to show on your UI if is required -&amp;gt; Create Posts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;description:&lt;/strong&gt; A brief description of the permission -&amp;gt; An User can create blog posts.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Permission&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Model&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$fillable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'display_name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'description'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="c1"&gt;// Relationship with roles.&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;roles&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;belongsToMany&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Role&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Role model
&lt;/h3&gt;

&lt;p&gt;To create the relationship between the permissions and the roles, we need to create a pivot table called &lt;code&gt;permission_role&lt;/code&gt; that has the &lt;code&gt;permission_id&lt;/code&gt; and &lt;code&gt;role_id&lt;/code&gt; fields.&lt;br&gt;
Here we can see the relationship between the permissions and the users too.&lt;br&gt;
The fields has the same meaning of the permissions table.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;name:&lt;/strong&gt; The role name -&amp;gt; reviewer&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;display_name:&lt;/strong&gt; The formated name -&amp;gt; Post Reviewer&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;description:&lt;/strong&gt; A brief description -&amp;gt; An User that can review a post and approve it.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Role&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Model&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$fillable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'display_name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'description'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="c1"&gt;// Relationship with permissions&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;belongsToMany&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Permission&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Relationship with users&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;hasMany&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  User Model
&lt;/h3&gt;

&lt;p&gt;Here we have the two escentials methods for our permissions system.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;role():&lt;/strong&gt; Is our relationship with the Role model.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;hasPermissionTo():&lt;/strong&gt; Here we receive as a parameter the permission name, and will return &lt;code&gt;true&lt;/code&gt; if the user have the permissions, and &lt;code&gt;false&lt;/code&gt; if don't have it.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Authenticatable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nv"&gt;$fillable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'first_name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'last_name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'role_id'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'password'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="c1"&gt;// Relationship with role&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;role&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;belongsTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Role&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="n"&gt;class&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Check if the user have the permission&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;hasPermissionTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$permissionName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;role&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;permissions&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$permissionName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Where implement this?
&lt;/h1&gt;

&lt;p&gt;Great, so we have our authorization logic, but now what?&lt;br&gt;
There are a few different ways you can implement this authorization logic in your Laravel application. Most you can use two different approaches for this:&lt;/p&gt;

&lt;h3&gt;
  
  
  Using Policies
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PostPolicy&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cd"&gt;/**
     * Determine if an user can create a post.
     */&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;User&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$user&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;hasPermissionTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'post.create'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Read more:&lt;/strong&gt; &lt;a href="https://laravel.com/docs/10.x/authorization#creating-policies"&gt;https://laravel.com/docs/10.x/authorization#creating-policies&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Using a Middleware
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CreatePostMiddleware&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Request&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Closure&lt;/span&gt; &lt;span class="nv"&gt;$next&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$permission&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nf"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;hasPermissionTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$permission&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nf"&gt;abort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;403&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Unauthorized action.'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Read more:&lt;/strong&gt; &lt;a href="https://laravel.com/docs/10.x/middleware#defining-middleware"&gt;https://laravel.com/docs/10.x/middleware#defining-middleware&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Summary
&lt;/h1&gt;

&lt;p&gt;Implementing authorization without using external libraries is not difficult, and it gives you more control over how your application handles authorization. By creating your own models and relationships, and implementing the &lt;code&gt;hasPermissionTo&lt;/code&gt; method, you can easily implement authorization in your Laravel application.&lt;/p&gt;

&lt;p&gt;That's all, I hope it can be helpful for you 🥳&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Migrating components from Option API to Composition API on Vue 🛠️</title>
      <dc:creator>Nico Montiel</dc:creator>
      <pubDate>Sun, 19 Feb 2023 20:45:08 +0000</pubDate>
      <link>https://dev.to/nicolasmontielf/migrate-option-api-to-composition-api-on-vue3-4o3p</link>
      <guid>https://dev.to/nicolasmontielf/migrate-option-api-to-composition-api-on-vue3-4o3p</guid>
      <description>&lt;p&gt;Today I will show you how to migrate your components from the "old" Option API to the new Composition API on Vue 3.&lt;/p&gt;

&lt;h3&gt;
  
  
  First of all, what is the composition api?
&lt;/h3&gt;

&lt;p&gt;Good question! The official documentation says&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Composition API is a set of APIs that allows us to author Vue components using imported functions instead of declaring options.&lt;br&gt;
Composition API is a built-in feature of Vue 3 and Vue 2.7. For older Vue 2 versions, use the officially maintained @vue/composition-api plugin. In Vue 3, it is also primarily used together with the &lt;code&gt;&amp;lt;script setup&amp;gt;&lt;/code&gt; syntax in Single-File Components.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Okay, great, but why should I use the Composition API?
&lt;/h3&gt;

&lt;p&gt;The primary benefit of the Composition API is that it enables clean, efficient logic reuse in the form of composable functions. It solves all the drawbacks of mixins, the primary logic reuse mechanism for the Options API.&lt;br&gt;
Also, it has more adeventajes like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;More Flexible Code Organization.&lt;/li&gt;
&lt;li&gt;Better Type Inference.&lt;/li&gt;
&lt;li&gt;Smaller Production Bundle and Less Overhead.&lt;/li&gt;
&lt;li&gt;Better use with Typescript.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Okay, so how are we going to do this?
&lt;/h3&gt;

&lt;p&gt;I prepared this Vuejs component and we will migrate it piece by piece.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;1. Components&lt;/strong&gt;.&lt;br&gt;
With the Composition API, you don't need to declare the components you want to use, just import them and they will be available in your template.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Props&lt;/strong&gt;.&lt;br&gt;
You can define the props in much the same way as before. You need to declare a variable (usually called props) and use the &lt;a href="https://vuejs.org/api/sfc-script-setup.html#defineprops-defineemits"&gt;defineProps&lt;/a&gt; method. This method is automatically available inside the &lt;code&gt;script setup&lt;/code&gt; tag.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;defineProps&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;cartId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;       
    &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;3. Event emitters&lt;/strong&gt;.&lt;br&gt;
As with props, you need to define a constant and use a method available within the &lt;code&gt;script setup&lt;/code&gt; tag. This is called &lt;a href="https://vuejs.org/api/sfc-script-setup.html#defineprops-defineemits"&gt;defineEmits&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;emit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;defineEmits&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;checkout&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;4. Data&lt;/strong&gt;&lt;br&gt;
With the data, we can now see much cleaner and more readable javascript. For the data on your component, you have two cases: data with reactivity, or a simple constant.&lt;/p&gt;

&lt;p&gt;For the data with reactivity, you need to import &lt;code&gt;ref&lt;/code&gt; and put the initial value of the variable inside the method.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ref&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;([])&lt;/span&gt; &lt;span class="c1"&gt;// This is the initial value, we are going to fill it later.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And for the constant variable, as easy as javascript.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;maybeAConstantObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;someKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;someValue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;anotherKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;anotherValue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;5. Methods&lt;/strong&gt;.&lt;br&gt;
Methods, like variables, are now just simple javascript functions, lets show some examples:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;addItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;proceedToCheckout&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Here you can also see how emit an event.&lt;/span&gt;
    &lt;span class="nf"&gt;emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;checkout&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;6. Computed properties&lt;/strong&gt;&lt;br&gt;
Okay, this is a bit more tricky, but still not complicated. To do this, we need to import the &lt;code&gt;computed&lt;/code&gt; method and inside it, we put a callback that returns the value of the property.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;computed&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;// So now this variable will return the sum of all the items in the cart, and it will be executed everytime the `items` change.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;computed&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;7. Watchers&lt;/strong&gt;&lt;br&gt;
As in some previous cases, you need to import the &lt;code&gt;watch&lt;/code&gt; method from Vue, and this takes two arguments; the first is the data you are watching (this should be reactive data, like &lt;code&gt;items&lt;/code&gt; in this case), and the second argument is a callback that is invoked when the data changes.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;watch&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;// The console.log will be executed every time items changes.&lt;/span&gt;
&lt;span class="nf"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cart items changed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;8. Created&lt;/strong&gt;&lt;br&gt;
So we don't have a specific onCreated here, we just need to create the function and initialise it inside the &lt;code&gt;script setup&lt;/code&gt;. Also, I leave here the list of &lt;a href="https://vuejs.org/guide/essentials/lifecycle.html#lifecycle-diagram"&gt;Lifecycles of a Vue component&lt;/a&gt; as a reference. Remember, here &lt;strong&gt;the DOM doesn't exist yet.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt; &lt;span class="nx"&gt;setup&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="c1"&gt;// This will be executed when the component is created.&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cart created&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;9. On Mount&lt;/strong&gt;&lt;br&gt;
This is a lifecycle that exists in the API, so we need to import it from vue. Inside it takes a callback that is executed after the component is mounted. Here you already have access to the DOM.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// This call to the endpoint will run when the component is mounted.&lt;/span&gt;
&lt;span class="nf"&gt;onMounted&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/api/cart/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cartId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;This is the final result:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h3&gt;
  
  
  To summarize
&lt;/h3&gt;

&lt;p&gt;Migrating from the Option API to the Composition API is not something complicated, from my own experience, after a few components, it will be an easy task for you.&lt;br&gt;
Now the question, should you do it? It's up to you, it's not necessary and if you prefer the Option API, you won't have any problem with it in the near future.&lt;/p&gt;

&lt;p&gt;If you have any recommendation or some case is missing, let me know and I can add it :)&lt;/p&gt;

&lt;p&gt;That's all, I hope it can be helpful for you 🥳&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How use FirebaseUI for user authentication on your React project 🔥</title>
      <dc:creator>Nico Montiel</dc:creator>
      <pubDate>Wed, 08 Feb 2023 23:24:21 +0000</pubDate>
      <link>https://dev.to/nicolasmontielf/how-use-firebaseui-for-user-authentication-on-your-react-project-32h7</link>
      <guid>https://dev.to/nicolasmontielf/how-use-firebaseui-for-user-authentication-on-your-react-project-32h7</guid>
      <description>&lt;p&gt;Hey! :D&lt;/p&gt;

&lt;p&gt;I will help you to configurate this tool from Firebase. Is super useful if you don't want to manage all the authentication of your users.&lt;br&gt;
If you want to read more about this and when to use it, please read the &lt;a href="https://firebase.google.com/docs/auth" rel="noopener noreferrer"&gt;documentation about authentication&lt;/a&gt;&lt;br&gt;
Also, you can use this same exact logic if you are writing your project in other framework like Svelte or Vue.&lt;/p&gt;

&lt;p&gt;To be able to use the Authentication of Firebase, you need to have a Firebase account and the firebase package in your project. I already make a tutorial about that, please &lt;a href="https://dev.to/nicolasmontielf/how-setup-firebase-on-your-frontend-project-1ap"&gt;read this before&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So now you are ready, so let's do this.&lt;/p&gt;
&lt;h4&gt;
  
  
  Create the Authentication service
&lt;/h4&gt;

&lt;p&gt;First, I recommend you to create a file called &lt;code&gt;auth.ts&lt;/code&gt;, here we can initialize the authentication layer.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;firebaseApp&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./firebase&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="c1"&gt;// This is the Firebase object from the previous tutorial&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;getAuth&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;firebase/auth&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;auth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getAuth&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firebaseApp&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h4&gt;
  
  
  Create the Login page on your project.
&lt;/h4&gt;

&lt;p&gt;So, let's create a login page. I didn't use any styles here, just the logic.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;With just that, you already have a login form with all the security from Firebase.&lt;br&gt;
This is how is showed on the screen:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F21ifywo0rs1v78jlffcq.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%2F21ifywo0rs1v78jlffcq.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I even put a random email there, and you can see how firebase already validate this for me.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbvgoviro3gq4hna3o5uc.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%2Fbvgoviro3gq4hna3o5uc.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://fir-ui-demo-84a6c.firebaseapp.com/" rel="noopener noreferrer"&gt;In this example&lt;/a&gt;, you can see how flexible and customizable the library is.&lt;br&gt;
For full documentation, you can see the github repository page &lt;a href="https://github.com/firebase/firebaseui-web" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Also, all the &lt;a href="https://github.com/firebase/firebaseui-web#configuration" rel="noopener noreferrer"&gt;options for configuration&lt;/a&gt; are also on their github repository.&lt;br&gt;
The documentation is super clear and robust about this library, but you can use this post as a starting point.&lt;/p&gt;

&lt;p&gt;That's all, I hope it can be helpful for you 🥳&lt;/p&gt;

</description>
      <category>firebase</category>
      <category>react</category>
      <category>vue</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How setup Firebase on your Frontend project 🔥</title>
      <dc:creator>Nico Montiel</dc:creator>
      <pubDate>Thu, 12 Jan 2023 04:07:39 +0000</pubDate>
      <link>https://dev.to/nicolasmontielf/how-setup-firebase-on-your-frontend-project-1ap</link>
      <guid>https://dev.to/nicolasmontielf/how-setup-firebase-on-your-frontend-project-1ap</guid>
      <description>&lt;p&gt;Hey! :D&lt;/p&gt;

&lt;p&gt;Here, I will help you to make the initial configuration of Firebase on your Frontend proyect. This also will be useful if you use vanilla Javascript or a framework like Vue or React.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configure the Firebase Account
&lt;/h3&gt;

&lt;p&gt;First, we need to &lt;a href="https://console.firebase.google.com" rel="noopener noreferrer"&gt;create an account on Firebase&lt;/a&gt; and add a New Project.&lt;/p&gt;

&lt;p&gt;After that, you will have access to the Console of your project. On the Project Settings you can get your credentials for the SDK that we going to install.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fgua7rf84eukekbeha1yc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fgua7rf84eukekbeha1yc.png" alt="Get your credentials for Firebase SDK" width="800" height="329"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's write some code!
&lt;/h3&gt;

&lt;p&gt;First, you need to install the SDK.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i firebase&lt;/code&gt; or &lt;code&gt;yarn add firebase&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After, I recommend to create a file called &lt;code&gt;firebase.ts&lt;/code&gt; or something like that, where you can initialize Firebase and just imported when is needed, instead of using it globally.&lt;/p&gt;

&lt;p&gt;Also, please avoid store your credentials directly on your code, there are packages like &lt;a href="https://www.npmjs.com/package/dotenv" rel="noopener noreferrer"&gt;dotenv&lt;/a&gt; to this type of stuffs.&lt;/p&gt;


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


&lt;p&gt;It's pretty simple, but let's explain some lines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Line 5:&lt;/strong&gt; Here we create our configuration object. This is exactly the same that you saw on your Firebase Console.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Line 6:&lt;/strong&gt; If you never saw the &lt;code&gt;import.meta.env.KEY_NAME&lt;/code&gt;, it's just the name convention that &lt;a href="https://vitejs.dev/guide/env-and-mode.html" rel="noopener noreferrer"&gt;Vite uses for the enviroment variables&lt;/a&gt;. So, if you don't use Vite, don't worry about this.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Line 17, 19:&lt;/strong&gt; Initialize and export your Firebase object.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Yeah, just like that. &lt;/p&gt;

&lt;p&gt;With this Firebase object, you can start using the different services that Firebase offers (Like databases, authentication, etc).&lt;br&gt;
Here is an example in their own &lt;a href="https://firebase.google.com/docs/database/web/start#web-version-9" rel="noopener noreferrer"&gt;documentation&lt;/a&gt;. This Firebase Object always is a parameter when you want to initialize other service.&lt;/p&gt;

&lt;p&gt;That's all, I hope it can be helpful for you 🥳&lt;/p&gt;

</description>
      <category>discuss</category>
    </item>
  </channel>
</rss>
