<?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: Emeka</title>
    <description>The latest articles on DEV Community by Emeka (@emekathegreat).</description>
    <link>https://dev.to/emekathegreat</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%2F783694%2F419db4a2-8c56-4e5c-95be-7923d6b0957b.jpg</url>
      <title>DEV Community: Emeka</title>
      <link>https://dev.to/emekathegreat</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/emekathegreat"/>
    <language>en</language>
    <item>
      <title>Bundling Code-Bases with Large File Structures</title>
      <dc:creator>Emeka</dc:creator>
      <pubDate>Sun, 14 Jul 2024 12:21:24 +0000</pubDate>
      <link>https://dev.to/emekathegreat/vite-spotify-and-the-power-of-genius-2044</link>
      <guid>https://dev.to/emekathegreat/vite-spotify-and-the-power-of-genius-2044</guid>
      <description>&lt;p&gt;Vite, Spotify and the Power of Genius.&lt;/p&gt;

&lt;h2&gt;
  
  
  Life is about Suffering
&lt;/h2&gt;

&lt;p&gt;And building web applications helps you understand a bit of what suffering is like. It is not supposed to be fun, or fast, or awesome, but you most certainly have to get the job done with whichever tools you choose.&lt;/p&gt;

&lt;p&gt;As a technologist, you are blessed with an array of tools that are needed to help you achieve your goals and whichever tool you choose has the potential to facilitate or completely destroy your chances of having a successful application, and given the fact that technology tools come and go, it’s up to you to update your tech stack every once-in-a new technology.&lt;/p&gt;

&lt;p&gt;Or else.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F59j71jvizctkqei79ej4.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F59j71jvizctkqei79ej4.gif" alt="Fireship.io" width="600" height="339"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My career as a technologist started with a simple Django application I built at the table in the small room that housed my techno-capital ambitions as a young immigrant. To fuel my love for writing, I built a blog I would use to host my articles and I named the domain (now defunct) after a nickname I had given myself at the time: &lt;a href="//djangoguyapp.herokuapp.com"&gt;Django-Guy&lt;/a&gt;. Six months later, my frontend enthusiasm had seen me switch from being a &lt;code&gt;Django guy&lt;/code&gt; to a Vue menace.&lt;/p&gt;

&lt;p&gt;Over a few months I took a rather weird deep dive into the Vue ecosystem and studied past Vue versions from Vue1 to Vue3. Then I went into NuxtJS and almost broke my back. After working with a few companies that use VueJS as their primary mode of communicating with their backend servers, all I can say is: &lt;/p&gt;

&lt;p&gt;Evan You is a genius.&lt;/p&gt;

&lt;h2&gt;
  
  
  Only the Paranoid Survive
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgfp84ue4db9kt95vjs82.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgfp84ue4db9kt95vjs82.png" alt="Frontend Penguins of Madagascar" width="800" height="476"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;VueJS has a lot of functionalities absent in more popular frontend frameworks like Svelte and React that make it powerful for building fast and scalable frontend frameworks. But the genius of VueJS and the Vue ecosystem lies not in the fundamentals of its technology, but in the genius of its founder.&lt;/p&gt;

&lt;p&gt;Much unlike Mark Zuckerberg’s top-down nature of problem solving that led to the wide-scale adoption of react, Evan You’s entire ideology is built around understanding problems deeply and solving them from the ground up to the customer.&lt;/p&gt;

&lt;p&gt;As evident in many of the &lt;a href="https://antfu.me/projects" rel="noopener noreferrer"&gt;tools&lt;/a&gt; in the VueJS and NuxtJS ecosystem they are designed to follow Evan’s method of solving specific problems, and although they may not all be perfect, they do precisely what they are meant to do and more importantly, they do it better than many other frameworks out there.&lt;/p&gt;

&lt;p&gt;But his genius doesn’t stop there.&lt;/p&gt;

&lt;h2&gt;
  
  
  Webpack and my mental health
&lt;/h2&gt;

&lt;p&gt;Everytime I hear the word &lt;em&gt;webpack&lt;/em&gt;, I get instant flashbacks from that one time I had a bug that almost jeopardized months of painstaking work. The same flashbacks I get from hearing the word &lt;code&gt;rest&lt;/code&gt;, from the nights and weekends I spent building on the Django Rest framework.&lt;/p&gt;

&lt;p&gt;Pardon me, I do not mean to scare you — Webpack is fun. And although I can’t say the same about the Django rest framework, I do wish it was faster.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3bdky380zzjz80pi9upq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3bdky380zzjz80pi9upq.png" alt="Traversty Media" width="800" height="676"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See, the beautiful thing about Webpack is that you get to see your code in all its glory. From the entry &lt;code&gt;webpack.config.js&lt;/code&gt; file, which gives connects your entire application for bundling in both development and production environments, through the entry directory configured by you — the 10x developer.&lt;/p&gt;

&lt;p&gt;I dare say that as a creative developer, the pains of webpack are definitely worth it considering the large amount of files that are bundled for the sake of rendering scenes, 2D and 3D elements to be manipulated in the DOM.&lt;/p&gt;

&lt;p&gt;But the struggle in this beauty is in its lack of speed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bundling away from the past
&lt;/h2&gt;

&lt;p&gt;The technology industry is built on speed. And the faster you are to adopt new technologies (both internally and externally), the better for you and your company. With that in mind, it think it is not too far fetched to say that most new companies underestimate how fast things can change and the need to update their systems. I think the same can be said for Webpack.&lt;/p&gt;

&lt;p&gt;Founded by Tobias Koppers, Sean Larkin, Johannes Ewald, Juho Vepsäläinen, Kees Kluskens, and open-source contributors Webpack was initially released on 19 February 2014 and up till now has remained the dominant bundling tool for modern web applications. Outperforming other native bundlers like gulp, grunt and browserify. I still believe it will remain relevant for at least a few more years but its influence has started to dwindle.&lt;/p&gt;

&lt;p&gt;From 2018, all native modern web browsers began to support ES6 modules. And like all &lt;a href="https://www.youtube.com/watch?v=LfU2Qu4MzZk" rel="noopener noreferrer"&gt;strategic inflection points&lt;/a&gt;, this created an opportunity for a new technology to emerge from the dust.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started with Vite — /:veet/
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmqlc4lru0nagbvhf77oy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmqlc4lru0nagbvhf77oy.png" alt="How fast are you?" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  A Spotify illustration
&lt;/h3&gt;

&lt;p&gt;According to new youtube videos, vite is what is supposed to replace webpack. And while I do not see it as a webpack replacement, I am definitely of the opinion that it offers a lot of performance improvements straight out the box. I say this because of the problems it has helped me solve in my work as a creative developer.&lt;/p&gt;

&lt;p&gt;So about a few months ago I started integrating the current playing song feature you see in many websites. My website was built with plain Javascript (no frameworks). And since it is bundled with webpack, I found it hard to make requests to and from the Spotify API in the spotify.js component I built because webpack didn’t run the frontend (I didn’t know that). It only bundled it to be served by the browser on request.&lt;/p&gt;

&lt;p&gt;After trying a few more solutions (including parcel), i stumbled on &lt;a href="https://github.com/whizzbbig/Floema-Vite/tree/main" rel="noopener noreferrer"&gt;the ViteJS implementation&lt;/a&gt; of &lt;a href="https://floema-v2.vercel.app" rel="noopener noreferrer"&gt;a website i built&lt;/a&gt; following a course by &lt;a href="https://bizar.ro" rel="noopener noreferrer"&gt;Luis Henrique Bizaro&lt;/a&gt; and instantly decided to see if ViteJS would solve my problem. It hasn’t solved it completely. But I had fun learning it so I’d like to share it with you.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm create vite --app name&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is the command that starts the Vite dev server, prebuilding your dependencies and bringing out template options for you to choose for your application. Vite4 currently supports Vue, React, Preact, Lit Element, Svelte, and even Vanilla. It’s not limited to these, we will keep adding more as we go. For my vite-spotify-app, I chose the vanilla js template because: I am not a man of many problems. I hate stress.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1yph44o8ur1dwxqxq8o5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1yph44o8ur1dwxqxq8o5.png" alt="Vite app" width="800" height="455"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then I proceeded to change the root to the &lt;code&gt;src&lt;/code&gt; folder I created which would house all my files, including the &lt;code&gt;.env&lt;/code&gt; file I would use to retrieve my environment variables which was a problem in webpack because I couldn’t access the &lt;code&gt;process.env&lt;/code&gt; object from my client in order to make API calls. For ViteJS you have to use &lt;code&gt;import.meta.env&lt;/code&gt; to access your environment variables for the root folder.&lt;/p&gt;

&lt;p&gt;To run the application, go to the terminal and type in &lt;code&gt;npm run dev&lt;/code&gt;. This would start the ViteJS dev server. Your terminal should show your &lt;code&gt;localhost&lt;/code&gt; which appears in 671ms for me which, unlike parcel and webpack, is rather fast.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F68jx7holeislr7c9pz96.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F68jx7holeislr7c9pz96.png" alt="vite running in vscode terminal" width="800" height="392"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For a more detailed illustration of the speed of ViteJS kindly take a look at &lt;a href="https://x.com/amasad/status/1355379680275128321" rel="noopener noreferrer"&gt;this video&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The spotify application should show your currenttly playing song after following the guide in the readme of the github folder linked above. This article doesn’t go too deep into spotify since that is not the main focus of this article. For an introduction to the spotify API check out my previous article on the topic.&lt;br&gt;
References&lt;/p&gt;

&lt;p&gt;Since this article is a walkthrough of my personal experience with VueJS and ViteJS along with a small tutorial on building an application with Vite, there’s not much of a reference list, everything you need to get started with ViteJS is here.&lt;/p&gt;

&lt;p&gt;However the links below are sources that can help you bolster your knowledge to go from a newbie to building more powerful applications with ViteJS&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://antfu.me/posts/vue-beijing-2021https://antfu.me/posts/vue-beijing-2021" rel="noopener noreferrer"&gt;Develop with Vite&lt;/a&gt;, a talk by Antfu at Vue Beijing Conference.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://youtu.be/89NJdbYTgJ8?si=_ClReEYRE9bIH1Hu" rel="noopener noreferrer"&gt;Vite crash course&lt;/a&gt;, by Travesty Media.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://v3.vitejs.dev/config/" rel="noopener noreferrer"&gt;Vite3 documentation&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Thank you so much for making it through this article and I wish you good success in building your first (or your next) ViteJS application. If you’re kind enough I’d love to know what you think about this article. &lt;/p&gt;

&lt;p&gt;For an intro on the Spotify Web API and how to integrate it to your app, check out the links below.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://dev.to/emekathegreat/crunching-the-spotify-api-3m3p"&gt;Crunching the spotify Web API&lt;/a&gt; by Chukwuemeka Mba&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://emeka-spotify-clone.netlify.app" rel="noopener noreferrer"&gt;Emeka Spotify Clone&lt;/a&gt; by Chukwuemeka Mba&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>vite</category>
      <category>spotify</category>
    </item>
    <item>
      <title>Crunching the Spotify Web API</title>
      <dc:creator>Emeka</dc:creator>
      <pubDate>Tue, 23 May 2023 23:12:37 +0000</pubDate>
      <link>https://dev.to/emekathegreat/crunching-the-spotify-api-3m3p</link>
      <guid>https://dev.to/emekathegreat/crunching-the-spotify-api-3m3p</guid>
      <description>&lt;p&gt;The Spotify API is one of the most widely used APIs in the API World. Since music is a major part of our lives, this API serves as tool that provides an extension of the individual from our private space into any application where we can stream our favorite artists.&lt;/p&gt;

&lt;p&gt;Depending on the permissions and access to which you have been granted by the Spotify developer team, you are allowed to grab and manipulate the data of any authorized user to suit the needs of your application.&lt;/p&gt;

&lt;p&gt;For example, applications like Discord, Last.fm, &lt;a href=""&gt;and many more&lt;/a&gt; make use of the Spotify API to provide a largely personalized listening experience to their users. &lt;/p&gt;

&lt;p&gt;How do these companies access and manipulate the API to suit their needs you ask? The answer is simple.&lt;/p&gt;

&lt;h1&gt;
  
  
  Send a request, get a response.
&lt;/h1&gt;

&lt;p&gt;While it is important to note that your use case will determine what endpoints you will make use of, there are certain things that are common to web applications that make use of the Spotify Web API which you would need to familiarize yourself with. &lt;/p&gt;

&lt;p&gt;You would need to understand how to perform the common CRUD operations you can perform with the API, this can be done by using &lt;a href="https://www.postman.com/postman/workspace/postman-team-collections/collection/7853927-755021ea-e6c9-47fd-a2b7-4348ea69914b?action=share&amp;amp;creator=19953081"&gt;Postman&lt;/a&gt; to take a detailed look at the endpoints shared by the Spotify Web API. &lt;/p&gt;

&lt;p&gt;To get started with the Spotify API you will need to log into the &lt;a href=""&gt;spotify developer dashboard&lt;/a&gt; and create a new project.&lt;/p&gt;

&lt;p&gt;After you click on create-new-app you will see a modal where you will be asked to input: the specifications of your project, host url, and other details.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdf01v8oz9haju4m2hmwo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdf01v8oz9haju4m2hmwo.png" alt="Project creation modal" width="800" height="1042"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you hit save, your project would be created and should look like this. This is to let Spotify know the url making requests to it's server is recognized and matches the information you provided. Now we can proceed with crunching the API.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fudpaywso0dhhuuh8fb85.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fudpaywso0dhhuuh8fb85.png" alt="your created project" width="800" height="565"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Authentication and Authorization
&lt;/h1&gt;

&lt;p&gt;To access a user's data via the API's endpoints, we would first need to authenticate the user.&lt;/p&gt;

&lt;p&gt;This process makes a request to the &lt;a href=""&gt;spotify account url&lt;/a&gt; with the required parameters and sends a hash token to your window url as a response.&lt;/p&gt;

&lt;p&gt;This token sent to your url will be used to authorize the user every time a request is made to the Spotify API. Yes. Every, single, time. &lt;br&gt;
The best part? It expires in 3600 milliseconds.&lt;/p&gt;

&lt;p&gt;To successfully make the request you would need to provide your:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Client ID&lt;/li&gt;
&lt;li&gt;Redirect URL (your website url or localhost url) &lt;/li&gt;
&lt;li&gt;The Spotify authorization url and &lt;/li&gt;
&lt;li&gt;The scope of your request&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;LOGIN.JS&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; function handleLogin() {
    const clientId = "aa7a764r6d6sd63t186314717ds7715318c";
    const redirectUrl = "http://localhost:3000";
    const apiUrl = "https://accounts.spotify.com/authorize";
    const scope = [
      "user-read-email",
      "user-read-private",
      "user-modify-playback-state",
      "user-read-currently-playing",
      "user-read-playback-state",
      "user-read-recently-played",
      "user-read-playback-position",
      "user-top-read",
    ];

    window.location.href = `${apiUrl}?client_id=${clientId}&amp;amp;redirect_uri=${redirectUrl}&amp;amp;scope=${scope.join(
      " "
    )}&amp;amp;response_type=token&amp;amp;show_dialog=false`;

    localStorage.clear();
  }
// Notice i set the dialog=false. If you set it to true you will be redirected to the spotify login page. If not, you continue like a boss.
// Also notice i cleared the local storage after logging in the user. I would explain why in a bit.


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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Hold your horses.
&lt;/h3&gt;

&lt;p&gt;After your user is logged in, you would notice a &lt;code&gt;hash-token&lt;/code&gt; is sent to the window url. We do not need the entire hash, we only need a part of it (the token). So we would get the hash from the window url and perform an operation on it to get the token using regular expressions. When we get the token we would supply it to our global state so it can be accessed throughout the entire application.&lt;/p&gt;

&lt;p&gt;For my application i used the useContext and useReducer hooks for global state management. So when I get the token, it is immediately dispatched to my global state to be accessed throughout the entire application. &lt;/p&gt;

&lt;p&gt;Since this article does not cover state management in react, &lt;a href="https://dev.to/ciphertron/usereducer-hook-to-the-rescue-2j48"&gt;this article&lt;/a&gt; by a former colleague of mine should explain in detail what exactly the Use Reducer Hook is and how to use it in state management.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
  const [{ token }, dispatch] = useStateProvider();
  useEffect(() =&amp;gt; {
    if (localStorage.getItem("spotify-token") === null || undefined) {
      localStorage.clear();
      const hash = window.location.hash;
      const token = hash.substring(1).split("&amp;amp;")[0].split("=")[1];
      window.localStorage.setItem("spotify-token", token);
      dispatch({ type: reducerCases.SET_TOKEN, token });
      window.location.hash = "";
    }
    const route = window.location.pathname;
    if (
      route === "/library" ||
      route === "/" ||
      route === "/home" ||
      route === "/search"
    ) {
      const token = localStorage.getItem("spotify-token");
      dispatch({ type: reducerCases.SET_TOKEN, token });
    }
  }, [token, dispatch]);


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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Local storage and Sesame squares
&lt;/h2&gt;

&lt;p&gt;If you remember that I cleared the local storage earlier, you deserve a bottle of wine!&lt;/p&gt;

&lt;p&gt;But why did I do this?&lt;/p&gt;

&lt;p&gt;It is because i need to store my token in the local storage for me to be able to access it after i refresh the page. Once you refresh your page, the API sends a request with the token to get the user's data for the application. If the token is available in the application's state, your requests will be successful if not they will be unsuccessful and you will be logged out and sent back to square 1.&lt;/p&gt;

&lt;p&gt;So I cleared the local storage to make way for the &lt;code&gt;spotify-token&lt;/code&gt; key with the &lt;code&gt;token&lt;/code&gt; value so i can access it when ever i refresh the page and dispatch it to the application state for use all over again.&lt;/p&gt;

&lt;p&gt;Simple innit? Great!&lt;/p&gt;

&lt;h1&gt;
  
  
  Data fetching and sample responses
&lt;/h1&gt;

&lt;p&gt;As we mentioned earlier, you would need the Spotify access token each time you make a request to the API in order to get a response. This has to happen asynchronously, since you will want to make sure you have your response before every other item on the page is loaded. &lt;/p&gt;

&lt;h2&gt;
  
  
  Get user's public playlists
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F94wsy3qrreko85jsypao.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F94wsy3qrreko85jsypao.png" alt="Image description" width="474" height="817"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To get all the user's total playlists, we would make use of the &lt;code&gt;Get Playlists Items&lt;/code&gt; endpoint &lt;code&gt;"https://api.spotify.com/v1/me/playlists"&lt;/code&gt; which appears on spotify developers platform without the /me as &lt;code&gt;https://api.spotify.com/v1/playlists&lt;/code&gt;. This request would be sent with authorization and content type headers to ensure the connection is secure.  &lt;/p&gt;

&lt;p&gt;PLAYLISTS.JS&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
export default function Playlists() {
  const [{ token, playlists }, dispatch] = useStateProvider();
  useEffect(() =&amp;gt; {
    const getPlaylistData = async () =&amp;gt; {
      const response = await axios.get(
        "https://api.spotify.com/v1/me/playlists",
        {
          headers: {
            Authorization: "Bearer " + `token`,
            "Content-Type": "application/json",
          },
        }
      );
      const { items } = response.data;
      const playlists = items.map(({ name, id, images }) =&amp;gt; {
        images = images[0].url;
        return { name, id, images };
      });
      dispatch({ type: reducerCases.SET_PLAYLISTS, playlists });
    };
    getPlaylistData();
  }, [token, dispatch]);

}

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

&lt;/div&gt;



&lt;p&gt;Once you dispatch your playlists data to your application state, you would be able to access the data through-out your entire application. Here is the response you would get if you log the first two playlists data (from my account) to the console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
0: 

id: "0RGvWGzBsi9XE200cmpRpE"
images : 
"https://mosaic.scdn.co/640/ab67616d0000b27306728f8480e37e0c4321b1f0ab67616d0000b273131635f182833dfee67ec2beab67616d0000b2738a96302eb81c56c50491b958ab67616d0000b273ec3de434caed2b0e969da43f"
name: "Party 💃🏼"
[[Prototype]] : Object

1 : 

id : "6o5RV6butrAw2Hl2CRkxlx"
images : "https://mosaic.scdn.co/640/ab67616d0000b2731e340d1480e7bb29a45e3bd7ab67616d0000b2734640a26eb27649006be29a94ab67616d0000b2734891d9b25d8919448388f3bbab67616d0000b273d1243ff8852e722747ead762"
name : "Spanish dance hits 💃🏼"

[[Prototype]] : Object


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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Playlists Response
&lt;/h2&gt;

&lt;p&gt;Since we deconstructed only the image, id, and title values from the return object, that is what we get from the API response. Otherwise we would get every value associated with the every playlist object. Which would look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
collaborative : false
description :  ""
external_urls :  { spotify : 'https://open.spotify.com/playlist/0RGvWGnHCSi9XE200cmpRpE'
}
href : "https://api.spotify.com/v1/playlists/0RGvWGzBsi9XE200cmpRpE"
id : "0RGvWGzBsi9XE0220cmpRpE"
images : 
(3) [{…}, {…}, {…}]
name : "Party 💃🏼"
owner : 
{
  display_name: 'Heleen Mas Opor Poel', 
  external_urls: {…}, 
  href: 'https://api.spotify.com/v1/users/21wga7eqgd237q2l227zl4eppyhi', 
  id: '21wg3ez7e4q2l227zl4eppyhi', 
  type: 'user', 
  …
}

primary_color : null
public : false
snapshot_id : "MzU5LDUxYmNjZaacbKJCAHCOHADASI0ZDY1ZDdlN2FkMzgyOWM1ZTk4YWU2Njc="
tracks : 
{. 
href: 'https://api.spotify.com/v1/playlists/afuuq3811ydb81y01/tracks', total: 314}
type : "playlist"
uri : "spotify:playlist:0RGvWGzBsi9XE200cmpRpE"


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

&lt;/div&gt;



&lt;p&gt;This is a simple example of how to make a request to and get a response directly from the Spotify API. If you liked this article please give it a like and subscribe to my YouTube Channel at... oh wait, there's no YouTube Channel.  &lt;/p&gt;

&lt;p&gt;See you later!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5vvn9t68k9c47wkouh28.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5vvn9t68k9c47wkouh28.png" alt="increases volume" width="541" height="541"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>spotify</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to implement Chromatic plugin x Figma addon for Vue and Storybook</title>
      <dc:creator>Emeka</dc:creator>
      <pubDate>Tue, 25 Oct 2022 13:53:41 +0000</pubDate>
      <link>https://dev.to/emekathegreat/how-to-implement-chromatic-plugin-x-figma-addon-for-vue-and-storybook-1mf6</link>
      <guid>https://dev.to/emekathegreat/how-to-implement-chromatic-plugin-x-figma-addon-for-vue-and-storybook-1mf6</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;Table of Contents&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is the chromatic plugin&lt;/li&gt;
&lt;li&gt;How it works + use cases&lt;/li&gt;
&lt;li&gt;Chromatic setup&lt;/li&gt;
&lt;li&gt;Vue project setup&lt;/li&gt;
&lt;li&gt;Figma plugin Integration with storybook&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What is the chromatic plugin ?
&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqqs044hxgu0gj9nh6fqh.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%2Fqqs044hxgu0gj9nh6fqh.png" alt="chromatic-logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The chromatic plugin is a third party software package developed by Storybook maintainers to help dev and design teams improve their workflows with storybook. It helps teams visualize built components, test and iterate faster with less manual work. &lt;/p&gt;

&lt;h3&gt;
  
  
  How it works
&lt;/h3&gt;

&lt;p&gt;The chromatic plugin synchronizes four different software to give you an optimal experience. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your internet hosting service (Github, Gitlab or bitbucket)&lt;/li&gt;
&lt;li&gt;Your preferred frontend framework (React or Vue) &lt;/li&gt;
&lt;li&gt;Storybook&lt;/li&gt;
&lt;li&gt;Figma&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Use cases include:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Building components&lt;/li&gt;
&lt;li&gt;Testing components&lt;/li&gt;
&lt;li&gt;Reviewing components&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Setting up Chromatic on your local repository
&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwcal5gwyv7mna0dtwd8c.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%2Fwcal5gwyv7mna0dtwd8c.png" alt="chromatic-workflow-image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first step is to ensure that you have built your Vue (this article is based on vue) application with storybook and that you have published your stories on storybook. &lt;/p&gt;

&lt;p&gt;Since this article does not discuss how to interact with storybook here's a &lt;a href="https://storybook.js.org/docs/react/get-started/introduction" rel="noopener noreferrer"&gt;link&lt;/a&gt; to the Storybook documentation to get you started on integrating your application with your frontend application. &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%2Fcn4b5s0052nortrpgpoq.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%2Fcn4b5s0052nortrpgpoq.png" alt="storybook-guide"&gt;&lt;/a&gt;&lt;br&gt;
Hit the dropdown button for the framework specific to you&lt;/p&gt;

&lt;p&gt;The next step is to create a chromatic account on &lt;code&gt;chromatic.com&lt;/code&gt; and connect your account to the hosting service that contains the project you want to work with: github, gitLab or bitbucket.&lt;/p&gt;

&lt;p&gt;After connecting your project you will see your project name on the top left corner of the screen and two commands to run on he center page. The second command contains your project token which is auto generated and should be added as a script to your &lt;code&gt;package.json&lt;/code&gt;&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%2Ft2crglksrq11ut0nd4kg.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%2Ft2crglksrq11ut0nd4kg.png" alt="commands"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is recommended that you add both scripts to your &lt;code&gt;package.json&lt;/code&gt; like so: &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%2Fjlot8u3sj1kg6vvhgdrs.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%2Fjlot8u3sj1kg6vvhgdrs.png" alt="scripts"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After you have done that, you have to ensure that chromatic recognizes all the stories on your repository by running your first build &lt;code&gt;npm run chromatic&lt;/code&gt;. Your builds will show up on your chromatic project like so:&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%2Fw2dmvl6ttt4xq8891i7j.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%2Fw2dmvl6ttt4xq8891i7j.png" alt="build"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each build shows the updated components and the changes made to the component library. &lt;/p&gt;

&lt;p&gt;Congratulations, you have successfully connected the chromatic plugin to your application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing the Figma Addon with Storybook
&lt;/h2&gt;

&lt;p&gt;The Figma addon helps you view your component's designs in storybook. To install it you would need to first run &lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install storybook-addon-designs&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;then add the addon to the array of addons in your &lt;code&gt;main.js&lt;/code&gt; file in the &lt;code&gt;.storybook&lt;/code&gt; folder. &lt;/p&gt;

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

module.exports = {
   stories=["../src/components/**/*.stories.js"],
   addons=["storybook-addon-designs"]
}


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

&lt;/div&gt;

&lt;p&gt;Your folder structure should look like this&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%2Fqlcgaxiu35kyxsh9lnii.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%2Fqlcgaxiu35kyxsh9lnii.png" alt="folder-structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After this is done, run &lt;code&gt;yarn storybook&lt;/code&gt; and your storybook should look like this with the design tab activated&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%2F8x4u7t25syby6axkkwlr.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%2F8x4u7t25syby6axkkwlr.png" alt="storybook-design-tab"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To get the specific design frame for a component into your component's story, you need to add the link to that frame or design to your component's story &lt;a href="https://storybook.js.org/docs/react/writing-stories/parameters" rel="noopener noreferrer"&gt;parameter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Example: for a primary Button component you would insert this in the &lt;code&gt;Button.stories.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;

export const Primary = Template.bind({});
Primary.args = {
  primary: true,
  label: 'Button',
};
Primary.parameters = {
  design: {
    type: "figma",
    url: "https://www.figma.com/file/ahdbchdsiuvgldiuagauidvgu/Project_Name?node-id=253%3eh",
  },};


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

&lt;/div&gt;

&lt;p&gt;For more details if you get stuck you should read the docs for each tool.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://storybook.js.org/docs/vue/get-started/introduction" rel="noopener noreferrer"&gt;Storybook&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.chromatic.com/docs/setup" rel="noopener noreferrer"&gt;Chromatic&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congratulations you have successfully implemented the chromatic plugin and the figma addon. See you when next I write something cool!&lt;/p&gt;

</description>
      <category>gitlab</category>
      <category>storybook</category>
      <category>figma</category>
      <category>vue</category>
    </item>
    <item>
      <title>User authentication with Axios, Vue Js and Nuxt Js.</title>
      <dc:creator>Emeka</dc:creator>
      <pubDate>Wed, 11 May 2022 20:58:16 +0000</pubDate>
      <link>https://dev.to/emekathegreat/user-authentication-with-axios-vue-js-and-nuxt-js-2o9d</link>
      <guid>https://dev.to/emekathegreat/user-authentication-with-axios-vue-js-and-nuxt-js-2o9d</guid>
      <description>&lt;p&gt;After struggling with user authentication in my nuxt app for quite a while, I was able to find a solution with the help of a friend and I would love to share it with you. Let's go! &lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;This article asumes that you are familiar with the basics of web development as well as the basics of vuejs. If you are not familiar with vue js &lt;a href="https://www.vuemastery.com/courses/intro-to-vue-3/intro-to-vue3" rel="noopener noreferrer"&gt;check out this turorial&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Project Structure
&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fctbk0rzz7sdjly65hkmc.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%2Fctbk0rzz7sdjly65hkmc.png" alt="Project Structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the project structure for our Nuxt Authentication with axios application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setup Nuxt Project
&lt;/h3&gt;

&lt;p&gt;I would be using npm so to follow along with this tutorial you will need to install:&lt;/p&gt;

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

npm install axios vuex-persist vuex


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;vuex-persist&lt;/strong&gt;&lt;br&gt;
If you are not familiar with &lt;strong&gt;vuex-persist&lt;/strong&gt;, it is a third party library in the vue ecosystem that saves the user's data in the browser's local or session storage (depending on your configuration). This enables the user to close a browser window and return with his details and data intact.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;vuex-toasted&lt;/strong&gt; helps display formatted messages to the user. Could be error messages or success messages.&lt;/p&gt;

&lt;p&gt;After installation your package.json 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%2Fvkkqpmwvdv18gdtrnty6.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%2Fvkkqpmwvdv18gdtrnty6.png" alt="Package.json"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ignore the packages not discussed in this tutorial. Focus on the versions of the ones used. Specifically: &lt;em&gt;Axios, vuex-toasted and vuex-persist&lt;/em&gt;. If you are using Nuxt you should have axios and vuex pre-installed so that saves you some time. &lt;/p&gt;

&lt;h4&gt;
  
  
  Backend Api routes
&lt;/h4&gt;

&lt;p&gt;Assuming you have a fully functional backend api with a base url of &lt;em&gt;localhost:3000/backend/api/&lt;/em&gt; you would need 2 routes: the register and login routes. For this tutorial we would be using:&lt;/p&gt;

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

- register route : auth/signup
- login route: auth/signin


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  vuex store
&lt;/h3&gt;

&lt;p&gt;The vuex store handles the state of our user data. From it we retrieve and store the user login details in the state function.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Import your vuex-persist plugin into your vuex store so it has access to your global state variables.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import VuexPersistence from 'vuex-persist'

function getPlugins() {
  const plugins = []

  if (process.browser) {
    const vuexLocal = new VuexPersistence({
      storage: window.localStorage,
    })

    plugins.push(vuexLocal.plugin)
  }
  return plugins
}

export const plugins = getPlugins()

export const state = () =&amp;gt; ({
  userDetails: [],
})

export const mutations = {
  setUserDetails(state, val) {
    state.userDetails = val
  },
}



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

&lt;/div&gt;

&lt;p&gt;We use the store to hold state data. Which in this case is the user's authentication info which helps us manage the flow of data throughout the application's runtime.&lt;/p&gt;

&lt;h2&gt;
  
  
  Login page:
&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqosnlp6n9i49lq7xs5r8.jpeg" 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%2Fqosnlp6n9i49lq7xs5r8.jpeg" alt="Login Page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  login.vue
&lt;/h3&gt;

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

&amp;lt;form @submit="login()" enctype="multipart/form-data" method="post"&amp;gt;
          &amp;lt;div class="fields"&amp;gt;
            &amp;lt;label for="email"&amp;gt;&amp;lt;strong&amp;gt;Email Address&amp;lt;/strong&amp;gt;&amp;lt;/label&amp;gt;
            &amp;lt;input type="email" name="email" v-model="email" /&amp;gt;

            &amp;lt;label for="email"&amp;gt;&amp;lt;strong&amp;gt;Password&amp;lt;/strong&amp;gt;&amp;lt;/label&amp;gt;
            &amp;lt;input type="password" name="email" v-model="password" /&amp;gt;
            &amp;lt;span class="forgot"&amp;gt;
              Use Uppercase, Lowercase and Numeric characters*
            &amp;lt;/span&amp;gt;
          &amp;lt;/div&amp;gt;
          &amp;lt;div&amp;gt;
            &amp;lt;div class="btn"&amp;gt;
              &amp;lt;button type="button" @click="login()"&amp;gt;
                Sign In
              &amp;lt;/button&amp;gt;
            &amp;lt;/div&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/form&amp;gt;


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

&lt;/div&gt;
&lt;h4&gt;
  
  
  Axios requests
&lt;/h4&gt;

&lt;p&gt;You would notice we get the user information from the store by calling &lt;code&gt;this.$store.state.userDetails&lt;/code&gt;. This is how user state is accessed from the store.&lt;/p&gt;

&lt;p&gt;Next we make a post request to the signin endpoint supplying the API with the user data in the data object. The API then checks if the user exists and returns a response of successful. &lt;/p&gt;

&lt;p&gt;We can now proceed to store the userdata in the local storage by committing the user data to the vuex store. The vuex persist plugin we imported in the store would save the data to enable persistent state between user sessions.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;script&amp;gt;
import axios from 'axios'
export default {
  data() {
    return {
      email: '',
      password: '',
      userInfo: this.$store.state.userDetails,
    }
  },
  methods: {
    async login() {
      const data = {
        email: this.email,
        password: this.password,
      }
      axios
        .post('localhost:3000/backend/api/auth/signin', data)
        .then((res) =&amp;gt; {
          const userData = res.data
          userData.user.token = userData.token
          this.$store.commit('setUserDetails', userData.user)
          this.$toasted.show('You have logged in successfully', {
            position: 'top-center',
            duration: 500,
            type: 'success',
          })
          this.$router.push('/home')
        })
        .catch((err) =&amp;gt; {
          this.$toasted.show(
            'Please enter the correct details and try again',
            err,
            {
              position: 'top-left',
              duration: 200,
              type: danger,
            }
          )
        })
    },
  },
}
&amp;lt;/script&amp;gt;


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

&lt;/div&gt;
&lt;h2&gt;
  
  
  Register Page:
&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuod4fn7aovoiniu6m2ny.jpeg" 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%2Fuod4fn7aovoiniu6m2ny.jpeg" alt="register.vue"&gt;&lt;/a&gt; &lt;/p&gt;
&lt;h3&gt;
  
  
  register.vue
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;form @submit="register()" enctype="multipart/form-data" method="post"&amp;gt;
          &amp;lt;div class="names"&amp;gt;
            &amp;lt;div class="name"&amp;gt;
              &amp;lt;label for="firstname"&amp;gt;&amp;lt;strong&amp;gt;First Name&amp;lt;/strong&amp;gt;&amp;lt;/label&amp;gt;
              &amp;lt;input type="text" name="firstname" v-model="firstname" /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div class="name"&amp;gt;
              &amp;lt;label for="lastname"&amp;gt;&amp;lt;strong&amp;gt;Last Name&amp;lt;/strong&amp;gt;&amp;lt;/label&amp;gt;
              &amp;lt;input type="text" name="lastname" v-model="lastname" /&amp;gt;
            &amp;lt;/div&amp;gt;
          &amp;lt;/div&amp;gt;
          &amp;lt;div class="fields"&amp;gt;
            &amp;lt;label for="email"&amp;gt;&amp;lt;strong&amp;gt;Email Address&amp;lt;/strong&amp;gt;&amp;lt;/label&amp;gt;
            &amp;lt;input type="email" name="email" v-model="email" /&amp;gt;

            &amp;lt;label for="password"&amp;gt;&amp;lt;strong&amp;gt;Password&amp;lt;/strong&amp;gt;&amp;lt;/label&amp;gt;
            &amp;lt;input type="password" name="password" v-model="password" /&amp;gt;
            &amp;lt;span class="forgot"&amp;gt;
              Use Uppercase, Lowercase and Numeric characters*
            &amp;lt;/span&amp;gt;
          &amp;lt;/div&amp;gt;

          &amp;lt;div class="btn"&amp;gt;
            &amp;lt;button type="button" @click="register()"&amp;gt;
              Sign Up
            &amp;lt;/button&amp;gt;
          &amp;lt;/div&amp;gt;
    &amp;lt;/form&amp;gt;


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

&lt;/div&gt;
&lt;h4&gt;
  
  
  axios requests
&lt;/h4&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;script&amp;gt;
import axios from 'axios'
export default {
  data() {
    return {
      firstname: '',
      lastname: '',
      email: '',
      password: '',
      error: null,
    }
  },

  methods: {
    async register() {
      const data = {
        firstname: this.firstname,
        lastname: this.lastname,
        email: this.email,
        password: this.password,
      }
      axios
        .post('localhost:3000/backend/api/auth/signup', data)
        .then((res) =&amp;gt; {
          const userData = res.data
          this.$toasted.show('You have registered successfully', {
            theme: 'primary',
            position: 'top-center',
            duration: 5000,
            type: 'success',
          })
          this.$router.push('/auth/login')
        })
    },
  },
}
&amp;lt;/script&amp;gt;



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

&lt;/div&gt;
&lt;h4&gt;
  
  
  Vuex Toast Notifications:
&lt;/h4&gt;

&lt;p&gt;This is a simple notification system that makes the helps create a good user experience. As seen above, the usage is simple. Specify your message as the first parameter to the toasted.show() method and then the specific configuration for the message type.&lt;/p&gt;

&lt;p&gt;Your application would access these plugins (vuex-toasted and vuex-persist) from the files below. &lt;/p&gt;

&lt;p&gt;Create a plugins folder and in it create two files like so:&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%2Fjha978pz2hmjp15zrv0t.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%2Fjha978pz2hmjp15zrv0t.png" alt="plugins folder"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We would use these files to host the configurations for vuex-persist and vuex-toast respectively.&lt;/p&gt;
&lt;h3&gt;
  
  
  vuex-persist.js
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import VuexPersistence from 'vuex-persist'

export default ({ store }) =&amp;gt; {
  new VuexPersistence({
    /* your options */
  }).plugin(store)
}



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

&lt;/div&gt;
&lt;h3&gt;
  
  
  vuex-toasted.js
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import Vue from 'vue'

import Toasted from 'vue-toasted'

if (process.browser) {
  Vue.use(Toasted)
}



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

&lt;/div&gt;

&lt;p&gt;As explained above, these files are meant to host the configurations for their respective packages. &lt;/p&gt;

&lt;p&gt;You should try to make these code examples work with your specific use-case. Once you do that everything should work fine.&lt;/p&gt;

&lt;p&gt;I am sure you are happy-crying now as you realize this long-ass article has finally come to an end. &lt;/p&gt;

&lt;p&gt;Either way, let me know in the comments what do you think about the code and please do give suggestions for improvements, they will be greatly appreciated!&lt;/p&gt;

</description>
      <category>vue</category>
      <category>nuxt</category>
      <category>authentication</category>
      <category>axios</category>
    </item>
  </channel>
</rss>
