<?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: Kelvin Chidothi</title>
    <description>The latest articles on DEV Community by Kelvin Chidothi (@kellskamuzu).</description>
    <link>https://dev.to/kellskamuzu</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%2F839791%2F000ed2b0-bdb2-46a9-b629-f1e24216ac1f.jpeg</url>
      <title>DEV Community: Kelvin Chidothi</title>
      <link>https://dev.to/kellskamuzu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kellskamuzu"/>
    <language>en</language>
    <item>
      <title>Nuxt 3 authentication with pinia</title>
      <dc:creator>Kelvin Chidothi</dc:creator>
      <pubDate>Tue, 21 Mar 2023 07:53:37 +0000</pubDate>
      <link>https://dev.to/kellskamuzu/nuxt-3-authentication-with-pinia-3bj7</link>
      <guid>https://dev.to/kellskamuzu/nuxt-3-authentication-with-pinia-3bj7</guid>
      <description>&lt;p&gt;A while ago, l wrote a post on Authenticating a Nuxt 2 application with a Laravel Sanctum API. As much as l like Nuxt.js because of it's cool features like middlewares, plugins, routing, SSR, Nuxt 3 has issues with authentication. Here are some of the reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Some packages have been removed in Nuxt 3 i.e. nuxt-auth&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No auth scaffolding &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Default configurations for axios, auth have been depreciated in nuxt.config.ts&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To write a good authentication logic in Nuxt 3, you have to come up with your own logic in Store, Middlewares (for routing). &lt;/p&gt;

&lt;p&gt;I tried sidebase package &lt;code&gt;@sidebase/nuxt-auth&lt;/code&gt; which is a good package but requires more customizations. Later l switched to pinia as documented here: &lt;a href="https://dev.to/rafaelmagalhaes/authentication-in-nuxt-3-375o"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This method work really well, kudos, but there's a problem again with persistence of state. &lt;/p&gt;

&lt;p&gt;To achive this, install the following package: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;yarn add -D @pinia-plugin-persistedstate/nuxt&lt;/code&gt; or&lt;br&gt;
&lt;code&gt;npm i -D @pinia-plugin-persistedstate/nuxt&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once this is installed at it under your modules array in nuxt.config.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 defineNuxtConfig({
  modules: [
    '@pinia/nuxt',
    '@pinia-plugin-persistedstate/nuxt',
  ],
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally add a persist prop under your defined store 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;// ~/store/auth.ts
import { defineStore } from 'pinia'

export const useStore = defineStore('auth', {
  state: () =&amp;gt; {
    return {
      authenticated: 'true',
    }
  },
  persist: true,
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will automatically instruct pinia to persist any data within it's store attribute. Pinia does this by either using a cookie or local storage, the choice is yours. Reference to this documentation for more global options for pinia persistence. &lt;a href="https://prazdevs.github.io/pinia-plugin-persistedstate/frameworks/nuxt-3.html"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>nuxtauth</category>
      <category>pinia</category>
      <category>nuxt3</category>
      <category>nuxt3auth</category>
    </item>
    <item>
      <title>Vite React Build Options - Rollup.js</title>
      <dc:creator>Kelvin Chidothi</dc:creator>
      <pubDate>Wed, 28 Sep 2022 14:12:56 +0000</pubDate>
      <link>https://dev.to/kellskamuzu/vite-react-build-options-rollupjs-2if6</link>
      <guid>https://dev.to/kellskamuzu/vite-react-build-options-rollupjs-2if6</guid>
      <description>&lt;p&gt;My recent project in React Boostraped with Vite gave me a tough time. Mostly because it was my first time using Vite, of course l used it cos it's rendering speed. l came across an issue where l had to add OneSignalSDKWorker file &lt;code&gt;OneSignalWorker.js&lt;/code&gt; in the root folder. In development it worked but not on production. This was because during build Vite ignored any file in the src and root folder that had no attribute/linkage to the project (to reduce size of the minified bundle).&lt;/p&gt;

&lt;p&gt;I had to find a work around it. The first attemt was to use &lt;code&gt;rollup.js&lt;/code&gt;. There are Build options for Vite in &lt;code&gt;vite.config.js&lt;/code&gt; that can be changed &lt;a href="https://vitejs.dev/config/build-options.html"&gt;&lt;/a&gt;. Here's what l did with the rollup options:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;build: {
    rollupOptions: {
      input: {
        app: './index.html',
        'OneSignalSDKWorker': './OneSignalSDKWorker.js',
      },
      output: {
        entryFileNames: assetInfo =&amp;gt; {
          return assetInfo.name === 'OneSignalSDKWorker' ? '[name].js' : 'assets/js/[name].js'
        }
      },
    },
  },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code block above we get our inputs. the app options is for the entry point and the second one is assigning a variable to the directory with the file. During build the file be placed in the dist root folder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exception:&lt;/strong&gt; This works with .js files and other es build types.&lt;/p&gt;

&lt;p&gt;For adding general files in the root folder, create a directory in src and name it public. You can now place all of your files into that folder. On build, all files will appear in the dist root directory.&lt;/p&gt;

&lt;p&gt;Read up more on rollup.js &lt;a href="https://rollupjs.org/guide/en/"&gt;&lt;/a&gt;&lt;br&gt;
Cheers!&lt;/p&gt;

</description>
      <category>vite</category>
      <category>react</category>
    </item>
    <item>
      <title>Uploading Multiple Files in Vue.js using a Laravel API</title>
      <dc:creator>Kelvin Chidothi</dc:creator>
      <pubDate>Mon, 16 May 2022 09:49:08 +0000</pubDate>
      <link>https://dev.to/kellskamuzu/uploading-multiple-files-in-vuejs-using-a-laravel-api-epb</link>
      <guid>https://dev.to/kellskamuzu/uploading-multiple-files-in-vuejs-using-a-laravel-api-epb</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YfMZ0caJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ch93j5e8t0udf0oaxtfz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YfMZ0caJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ch93j5e8t0udf0oaxtfz.png" alt="Image description" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Recently l wanted to upload documents from Vue.js to a Laravel backend. All API's were set up and were working in Postman. Doing in vue.js was a bit of a problem. l was using Vuetify &lt;a href="https://vuetifyjs.com/"&gt;&lt;/a&gt; for the styling so l used a v-file-input set to &lt;code&gt;multiple&lt;/code&gt; using the predefined prop.&lt;/p&gt;

&lt;p&gt;On upload, l was using Axios. Basic stuff. To attach documents l created an instance of &lt;code&gt;FormData()&lt;/code&gt; and appended the documents &lt;code&gt;formData.append('images[]', this.images)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In  my controller in Laravel, l was looping over the array of images and storing them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;foreach($request-&amp;gt;file('images') as $image){
  $image-&amp;gt;store('docs');
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This implementation failed and l did alot of modifications and turns out l had to loop over the documents also in Vue.js 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;this.images.foreach((image, index) =&amp;gt; { formData.append('images[]', image) });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This finally worked and l hope it works for you too!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Generating an APK in React Native CLI</title>
      <dc:creator>Kelvin Chidothi</dc:creator>
      <pubDate>Fri, 06 May 2022 09:27:41 +0000</pubDate>
      <link>https://dev.to/kellskamuzu/bundling-an-apk-in-react-native-cli-2f4d</link>
      <guid>https://dev.to/kellskamuzu/bundling-an-apk-in-react-native-cli-2f4d</guid>
      <description>&lt;h2&gt;
  
  
  React Native
&lt;/h2&gt;

&lt;p&gt;has gained popularity over the years, with the whole concept of cross-platform development developer has flocked to it. l am one of the developers. l started React Native about 2 years ago and l did a bit of CLI before loving Expo&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Debate is still on about what is better CLI or Expo.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After a while not using CLI, l ended up wanting to use it for some project. l settled my Android environment and everything but everytime l wanted to generate a stand alone debug apk using &lt;code&gt;gradlew assembleDebug&lt;/code&gt; it would build an apk that still required the Metro server. l mean how absurd. l tried building it in Android Studio and same issue came up.&lt;/p&gt;

&lt;p&gt;l discovered that they now commented some build features in &lt;code&gt;/android/app/build.gradle&lt;/code&gt;file. They are now optional and everytime you want a standalone apk you need to uncomment some few lines.&lt;/p&gt;

&lt;p&gt;For example these lines preceeding the hemes engine use in build:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bundleInDebug: true,
bundleAssetName: "index.android.bundle
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So l thought of sharing this, if anyone ever get confused to as what's happening. Thank you for reading!&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>react</category>
      <category>android</category>
    </item>
    <item>
      <title>Mantainig Session in Nuxt JS Laravel Authentication API</title>
      <dc:creator>Kelvin Chidothi</dc:creator>
      <pubDate>Mon, 02 May 2022 23:02:45 +0000</pubDate>
      <link>https://dev.to/kellskamuzu/mantainig-session-in-nuxt-js-laravel-authentication-api-50hb</link>
      <guid>https://dev.to/kellskamuzu/mantainig-session-in-nuxt-js-laravel-authentication-api-50hb</guid>
      <description>&lt;p&gt;l had an issue in my recent project. Well based on the title, you guessed right "Mantaining session". As much as NuxtJS provides a proper configuration of API integrations and ofcourse authentication with &lt;code&gt;**@nuxt/next-auth**&lt;/code&gt; package, it's somehow challenging to keep session.&lt;/p&gt;

&lt;p&gt;In my project l was using Laravel as the backend framework and created API's guarded with sactum. After configuring everything as per (&lt;a href="https://auth.nuxtjs.org/schemes/local"&gt;https://auth.nuxtjs.org/schemes/local&lt;/a&gt;). It was really hard. *&lt;em&gt;Session was being removed on reload page of the nuxtjs app. &lt;br&gt;
*&lt;/em&gt;&lt;br&gt;
So here was a work around to it. I added vuex-persist package to the nuxt project using yarn and created a plugin. l added the plugin in the plugins sections in nuxt.config.js and automatically my data was saved in a cookie as much as session was active!&lt;/p&gt;

&lt;p&gt;l hope you guys read more about vuex-persist or other related libraries. If any questions let me know.&lt;br&gt;
👌👌&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>nuxt</category>
      <category>vue</category>
    </item>
  </channel>
</rss>
