<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Lughni Alfadjri on Medium]]></title>
        <description><![CDATA[Stories by Lughni Alfadjri on Medium]]></description>
        <link>https://medium.com/@lughnizaid?source=rss-50e42dc3020a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*IgBWvypbxK80f7K57JhrUQ.jpeg</url>
            <title>Stories by Lughni Alfadjri on Medium</title>
            <link>https://medium.com/@lughnizaid?source=rss-50e42dc3020a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 14:49:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lughnizaid/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building A Localised Places Autocomplete with Vue.js, Tailwind, and Google Places API]]></title>
            <link>https://medium.com/geekculture/building-a-localised-places-autocomplete-with-vue-js-tailwind-and-google-places-api-part-1-14cb83cdc659?source=rss-50e42dc3020a------2</link>
            <guid isPermaLink="false">https://medium.com/p/14cb83cdc659</guid>
            <category><![CDATA[product-development]]></category>
            <category><![CDATA[tailwind]]></category>
            <category><![CDATA[shipping]]></category>
            <category><![CDATA[google-places]]></category>
            <category><![CDATA[vue]]></category>
            <dc:creator><![CDATA[Lughni Alfadjri]]></dc:creator>
            <pubDate>Sat, 23 Oct 2021 09:48:47 GMT</pubDate>
            <atom:updated>2021-10-25T13:01:35.323Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XvQiIzpg2tyPV1O0J7Iv1Q.png" /></figure><p>Filling address in the checkout process is one of the most important steps in almost every digital platforms, especially in the Ecommerce. It is so important that any E-commerces platforms generally will enhance this process to be as easy as possible for the users, to improve users experience, which can lead to the higher conversion during user journey.</p><p>From product team perspective, Places autocomplete is very beneficial. <strong>The study by Shopify shows that Google places autocomplete reduce 20% of time during the checkout, which lead to the higher conversion.</strong></p><p>However, it is also interesting to see it from technological perspective, and how this feature is implemented. Understanding the logic behind it will help product team to communicate it better with the developers and also to discuss the solution together when we things are not going as we planned, or when we want to enhance the autocomplete features even more to support business goals.</p><p><strong>In this article, I would like to share my understanding how to build a localised places autocomplete (specific country) with Vue, Tailwind, and Google Places API.</strong></p><p>To build a localised places autocomplete, there are three main perquisites:</p><ol><li>Vue</li><li>Tailwind</li><li>Google Places API</li></ol><p>We will build this step by step, so that we can get better insight how a localised places autocomplete is implemented with Vue, Tailwind, and Google Places API.</p><h3>Build Vue Project</h3><p>First, you need to build a Vue Project. To build A Vue Project, you can use Vue CLI. To install it in your system, we can use this command:</p><pre>npm install -g @vue/cli</pre><p>Now, using Vue CLI, you can use Vue Create to create a Vue project with this command:</p><pre>vue create places-autocomplete</pre><p>After creating a Vue Project, you need to run your vue project and see it in your local using this command</p><pre>npm run serve</pre><p>When running the local server is started, you can open your browser to localhost:8080. You should see this by default:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/30/0*u35UBzOt79OJziLl" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*foLofWlACEgg5CDl.png" /></figure><p>Perfect!. Now you are done in creating a Vue Project. Now its time to install Tailwind and integrate it with Vue.js.</p><h3>Install Tailwind</h3><p>The following step is to install Tailwind and integrate it with Vue.js. To install Tailwind, we can use npm or yarn. However in this case, we will use npm. If you are interested to know more, you can find it <a href="https://tailwindcss.com/docs/installation"><strong>here</strong></a></p><pre><br>npm install tailwindcss --save-dev</pre><p>After installing Tailwind, we will be able to see the tailwindcss in devDependencies inside package.json file.</p><pre>{</pre><pre>  &quot;devDependencies&quot;: {</pre><pre>     &quot;tailwindcss&quot;: &quot;^2.2.16&quot;</pre><pre>  }<br>}</pre><h3>Create a configuration file</h3><p>Next, we need to use the Tailwind command that has been provided to create a configuration file.</p><pre>./node_modules/.bin/tailwind init tailwind.js</pre><p>After using the command above, we will see a new file called tailwind.js in the root of our project, which is the basic Tailwind configuration.</p><h3>Create a PostCSS</h3><p>Now we need to configure PostCSS to make sure Tailwind runs. The file postcss.config.js is located in the root. If you can not find one, you can create it.</p><pre>module.exports = {<br>  plugins: {<br>    tailwindcss: {},<br>    autoprefixer: {},<br>  }<br>}</pre><h3>Create a CSS file</h3><p>Now we can create a CSS file in src/assets/css/tailwind.css and add</p><pre>@tailwind base;<br>@tailwind components;<br>@tailwind utilities;</pre><p>In this file, if you want, you can override the tailwind classes with your own CSS in @layer base, @layer components, @layer utilities . But as the goal of this article is not only about the design, we will leave it empty.</p><h3>Import tailwind.css in our Vue app</h3><p>After the process above, the last step will be to import it in our main.js.</p><pre>import &#39;@/assets/css/tailwind.css&#39;</pre><p>Now, if we insert tailwind classes in our template, we will see some changes. Perfect!</p><h3>Setting up Google Places API</h3><p>Setting up Google Places API is straightforward! However, to be able to use Google Places API, we need to enable billing for your project, as Google Place API require billing.</p><h3>Enable the APIs</h3><p>After enabling the billing, we need to enable the places API. We need to go to the project chosen and click the enable APIs and services.</p><figure><img alt="Click Enable APIs and Services" src="https://cdn-images-1.medium.com/max/420/1*Red-tAKcK4kxuhWQEQ0GEg.png" /></figure><p>There will be a list of APIs. We need to click the maps section, and we will be able to see the list of map APIs. In that section, we can see there are 17 maps APIs that Google provided.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*oKBubSX7W5nEBCX0-bjFUw.png" /></figure><p>There are two main APIs that we need to enable, which are Places API and Maps Javascript API. There might be a question, why we also need to enable Maps Javascript API. Well, while we use Places API to implement autocomplete, unfortunately Places API will not work unless we enable Maps Javascript API, for Places API is part of Maps Javascript API. Therefore, it is mandatory to implement Maps Javascript API.</p><h3>Places API in Vue</h3><p>I am glad that you come this far. Now lets insert places API in our Vue project. To do that, First we need to get the API keys.</p><p>We can access API keys in your Google Cloud Platform. In the tabs, click credentials tabs, and you will be able to find your Api keys in the key column.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*-5xFaLeka4hOmGyZmqsVhg.png" /></figure><p>After having the API key, we need to insert javascript library with API key in the index.html file inside Vue project. The index.html is generally located inside public folder.</p><pre>&lt;script src=&quot;<a href="https://maps.googleapis.com/maps/api/js?libraries=places&amp;key=[YOUR_API_KEY">https://maps.googleapis.com/maps/api/js?libraries=places&amp;key=[YOUR_API_KEY</a>]&quot;&gt;&lt;/script&gt;</pre><p>Perfect! It is a long road, but now we have a Vue project with tailwind and Places API, that is ready to use inside of the project. Bravo!</p><h3>Create Shipping Address Form</h3><p>Finally, lets do the UI for Shipping Form. We will create a form with 7 input information, which are Name, Street, City, State, Postal Code, Phone, and Email. Therefore, there will be 7 input field on it.</p><pre>&lt;form&gt;</pre><pre> &lt;h3&gt;Shipping Address&lt;/h3&gt;</pre><pre> &lt;input type=&quot;text&quot; placeholder=&quot;Name&quot;/&gt;</pre><pre> &lt;input type=&quot;text&quot; placeholder=&quot;Street&quot;/&gt;</pre><pre> &lt;input type=&quot;text&quot; placeholder=&quot;City&quot;/&gt;</pre><pre> &lt;input type=&quot;text&quot; placeholder=&quot;State&quot;/&gt;</pre><pre> &lt;input type=&quot;text&quot; placeholder=&quot;Postal Code&quot;/&gt;</pre><pre> &lt;input type=&quot;text&quot; placeholder=&quot;Phone&quot;/&gt;</pre><pre> &lt;input type=&quot;text&quot; placeholder=&quot;Email&quot;/&gt;</pre><pre> &lt;button&gt; Continue &lt;/button&gt;</pre><pre>&lt;/form&gt;</pre><h3>Design the UI with Tailwind</h3><p>Without styling, shipping field will looks gloomy, so lets design it with Tailwind. One thing that i like about Tailwind is that it has more classes option to design our UI, compared to other css frameworks.</p><p>Lets say the designer already gave the shipping form design as below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*PZsK-tc78ntBaFu7bCIyrg.png" /></figure><p>In one or two glances, UI developers tend to know and get the feeling how to implement this, what property and value that need to be implemented such as flex, parents divs (state, postal code, phone, and email), input background, placeholder colour, padding, and button. In this article, I would like to share how we can implement this UI with tailwind step by step.</p><p>Firstly, lets make 1 title, 7 input, and 1 button with full width, where the input have black border, margin-top 1.25rem each, and padding 1 rem. Also to make title font size into bold.</p><pre>&lt;div class=&quot;container form-section mx-auto px-4 font-sans&quot;&gt;</pre><pre>&lt;form&gt;</pre><pre> &lt;h3 class=&quot;text-xl mb-8 mx-auto text-center font-bold&quot;&gt;Shipping Address&lt;/h3&gt;</pre><pre> &lt;div class=&quot;mb-4&quot;&gt;</pre><pre>  &lt;input type=&quot;text&quot; placeholder=&quot;Name&quot; class=&quot;w-full py-2 px-4  border-2 border-black&quot; /&gt;</pre><pre>  &lt;input type=&quot;text&quot; placeholder=&quot;Street&quot; class=&quot;w-full py-2 px-4 border-2 border-black mt-5&quot;/&gt;</pre><pre>  &lt;input type=&quot;text&quot; placeholder=&quot;City&quot; class=&quot;w-full py-2 px-4 border-2 border-black mt-5&quot; /&gt;</pre><pre>  &lt;input type=&quot;text&quot; placeholder=&quot;State&quot; class=&quot;w-full py-2 px-4 border-2 border-black mt-5&quot; /&gt;</pre><pre>  &lt;input type=&quot;text&quot; placeholder=&quot;Postal Code&quot; class=&quot;w-full py-2 px-4 border-2 border-black mt-5&quot; /&gt;</pre><pre>  &lt;input type=&quot;text&quot; placeholder=&quot;Phone&quot; class=&quot;w-full py-2 px-4 border-2 border-black mt-5&quot; /&gt;</pre><pre>  &lt;input type=&quot;text&quot; placeholder=&quot;Email&quot; class=&quot;w-full py-2 px-4 border-2 border-black mt-5&quot; /&gt;</pre><pre>  &lt;button class=&quot;w-full py-2 px-4 border-2 border-black mt-5&quot; type=&quot;button&quot;&gt;</pre><pre>  Continue</pre><pre>  &lt;/button&gt;</pre><pre> &lt;/div&gt;</pre><pre>&lt;/form&gt;</pre><pre>&lt;/div&gt;</pre><p>The code above will show the UI as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*u24gnWZ3hHy4JAtE2iQdgw.png" /></figure><p>The next step will be displaying state, postal code, phone, and email side by side. We can use some approach such as Grid or Flex. In this example, we will use flex.</p><pre>&lt;div class=&quot;flex&quot;&gt;</pre><pre> &lt;input type=&quot;text&quot; placeholder=&quot;State&quot; class=&quot;w-full py-2 px-4 border-2 border-black mt-5 mr-1&quot; /&gt;</pre><pre> &lt;input type=&quot;text&quot; placeholder=&quot;Postal Code&quot; class=&quot;ml-1 w-full py-2 px-4 border-2 border-black mt-5 ml-1&quot; /&gt;</pre><pre> &lt;/div&gt;</pre><pre> &lt;div class=&quot;flex&quot;&gt;</pre><pre> &lt;input type=&quot;text&quot; placeholder=&quot;Phone&quot; class=&quot;w-full py-2 px-4 border-2 border-black mt-5 mr-1&quot; /&gt;</pre><pre> &lt;input type=&quot;text&quot; placeholder=&quot;Email&quot; class=&quot;w-full py-2 px-4 border-2 border-black mt-5 ml-1&quot; /&gt;</pre><pre>&lt;/div&gt;</pre><p>The code above will show new UI for State, Postal Code, Phone, and Email.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*J0XPU5Z0gYWnDZC1gnW8Fw.png" /></figure><p>Wonderful, the next ones will be to change the title colour, change the input field background, make the field has a radius, and change the background and border colour when the field is in focus.</p><pre>&lt;form&gt;</pre><pre> &lt;h3 class=&quot;text-xl mb-8 mx-auto text-center font-bold text-purple-600&quot;&gt;Shipping Address&lt;/h3&gt;</pre><pre> &lt;div class=&quot;mb-4&quot;&gt;</pre><pre> &lt;input type=&quot;text&quot; placeholder=&quot;Name&quot; class=&quot;bg-gray-200 border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500&quot; /&gt;</pre><pre> &lt;input type=&quot;text&quot; placeholder=&quot;Street&quot; class=&quot;mt-5 bg-gray-200 border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500&quot;/&gt;</pre><pre> &lt;input type=&quot;text&quot; placeholder=&quot;City&quot; class=&quot;mt-5 bg-gray-200 border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500&quot; /&gt;</pre><pre> &lt;div class=&quot;flex&quot;&gt;</pre><pre>  &lt;input type=&quot;text&quot; placeholder=&quot;State&quot; class=&quot;mr-1 mt-5 bg-gray-200 border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500&quot; /&gt;</pre><pre>  &lt;input type=&quot;text&quot; placeholder=&quot;Postal Code&quot; class=&quot;ml-1 mt-5 bg-gray-200 border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500&quot; /&gt;</pre><pre> &lt;/div&gt;</pre><pre> &lt;div class=&quot;flex items-center justify-between&quot;&gt;</pre><pre>  &lt;input type=&quot;text&quot; placeholder=&quot;Phone&quot; class=&quot;mr-1 mt-5 bg-gray-200 border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500&quot; /&gt;</pre><pre>  &lt;input type=&quot;text&quot; placeholder=&quot;Email&quot; class=&quot;ml-1 mt-5 bg-gray-200 border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500&quot; /&gt;</pre><pre> &lt;/div&gt;</pre><pre> &lt;button class=&quot;cursor-pointer mt-7 w-full shadow bg-purple-600 hover:bg-purple-600 focus:shadow-outline focus:outline-none text-white font-bold py-2 px-4 rounded mt-4&quot; type=&quot;button&quot;&gt;</pre><pre> Continue</pre><pre> &lt;/button&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/form&gt;</pre><p>The code above will display the new UI for the shipping form, and when the user is in one of the fields, the border colour and the input field background will change into white and purple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*uz8Zn59SMEi9DxyTnzzn8A.png" /></figure><p>Finally, the last step for the UI designing. As being seen previously, the final design has a leaner shipping form compared with the image above. The final design of shipping form is wrapped with a shadow to help the users easily notice the shipping form element.</p><p>To do that, all we need to do is adding classes of this form and styling it by giving border, shadow, and padding.</p><pre>&lt;div class=&quot;container mt-12 form-section mx-auto px-4 font-sans&quot;&gt;</pre><pre>&lt;form class=&quot;shadow-md rounded-lg px-8 py-6 mb-4 border-2 border-gray-200&quot;&gt; <strong>&lt;!-- New Change --&gt;</strong></pre><pre>&lt;h3 class=&quot;text-xl mb-8 mx-auto text-center font-bold text-purple-600&quot;&gt;Shipping Address&lt;/h3&gt;</pre><pre>&lt;div class=&quot;mb-4&quot;&gt;</pre><pre>&lt;input type=&quot;text&quot; placeholder=&quot;Name&quot; class=&quot;bg-gray-200 border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500&quot; /&gt;</pre><pre>&lt;input type=&quot;text&quot; placeholder=&quot;Street&quot; class=&quot;mt-5 bg-gray-200 border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500&quot; /&gt;</pre><pre>&lt;input type=&quot;text&quot; placeholder=&quot;City&quot; class=&quot;mt-5 bg-gray-200 border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500&quot; /&gt;</pre><pre>&lt;div class=&quot;flex&quot;&gt;</pre><pre>&lt;input type=&quot;text&quot; placeholder=&quot;State&quot; class=&quot;mr-1 mt-5 bg-gray-200 border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500&quot; /&gt;</pre><pre>&lt;input type=&quot;text&quot; placeholder=&quot;Postal Code&quot; class=&quot;ml-1 mt-5 bg-gray-200 border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500&quot; /&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;div class=&quot;flex items-center justify-between&quot;&gt;</pre><pre>&lt;input type=&quot;text&quot; placeholder=&quot;Phone&quot; class=&quot;mr-1 mt-5 bg-gray-200 border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500&quot; /&gt;</pre><pre>&lt;input type=&quot;text&quot; placeholder=&quot;Email&quot; class=&quot;ml-1 mt-5 bg-gray-200 border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500&quot; /&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;button class=&quot;cursor-pointer mt-7 w-full shadow bg-purple-600 hover:bg-purple-600 focus:shadow-outline focus:outline-none text-white font-bold py-2 px-4 rounded mt-4&quot; type=&quot;button&quot;&gt;</pre><pre>Continue</pre><pre>&lt;/button&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/form&gt;</pre><pre>&lt;/div&gt;</pre><p>The change above will show the new UI for shipping from as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*RHklZZdf1RBpuNilGBvaMg.png" /></figure><h3>Creating Autocomplete Address</h3><p>Alriight (this words remind me of my good friend), we finished the UI implementation with Tailwind. It is so much fun is it?. With Tailwind, we can do UI development faster. In addition, compared to other CSS framework, Tailwind provide wider range of customisation with their classes.</p><p>The next step will be implementing Autocomplete location with Google Places API. We will implement it in the “street” input field. Therefore we will focus on this field.</p><h3><strong>Function inside Mounted Hook</strong></h3><p>There are two main things we need to emphasise to create Autocomplete address. First, we will need to call the data from Google Places API and display it when the user start typing any address. Secondly, we will execute it in Mounted Hook.</p><p><strong>What is mounted hook?</strong> This is one of the most commonly used lifecycle hook in Vue. Vue calls the mounted hook when a component is added to the DOM. It is generally used to send a request to fetch data that the component will render.</p><pre>mounted() {</pre><pre>}</pre><p>Perfect, now we will need to send a request to fetch data inside Mounted hook so that we can show autocomplete in our street input field. Google Places API has documentation <a href="https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete"><strong>here</strong></a>, giving a complete overview to implement it. In the code above, it shows the autocomplete and is rendered in one of the id elements.</p><pre>mounted() {</pre><pre> var autocomplete = new google.maps.places.Autocomplete(</pre><pre> document.getElementById(&quot;autocomplete&quot;),</pre><pre> );</pre><pre>}</pre><p>The next step will be to put the the id (autocomplete) in one of the input fields to render the autocomplete. As we want to put it in street input field, we can put it there.</p><pre>&lt;input id=&quot;autocomplete&quot; type=&quot;text&quot; placeholder=&quot;Street&quot; class=&quot;mt-5 bg-gray-200 border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500&quot;</pre><p>Wonderful, now if we start to type in street input field, it will display autocomplete.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*R0wmUSc8-4asTuu7k7jOtQ.png" /></figure><p>Perfect!. Now when we type M, some autocomplete suggestion will be shown. But there are still problems. We want it to be localised to specific place. How we can implement it?. To do that, we can set the country limitation for the autocomplete.</p><pre>mounted() {</pre><pre> var autocomplete = new google.maps.places.Autocomplete(</pre><pre> document.getElementById(&quot;autocomplete&quot;),</pre><pre> );</pre><pre> autocomplete.setComponentRestrictions({ <em>// restrict the country</em></pre><pre> country: [&quot;de&quot;]</pre><pre> })</pre><pre>}</pre><p>The code above shows how the function will just shows the autocomplete from specific country (Germany), instead of everywhere. You can set in any countries, and you can find the documentation of country restriction <a href="https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-multiple-countries"><strong>here</strong></a><strong>. T</strong>he country code must be in two character, ISO 3166–1 Alpha-2 compatible country code. You can find the country code <a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2"><strong>here</strong></a><strong>.</strong></p><p>Now if we type M, it will show one of the cities or areas in Germany.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*oe58wrJe_vRfD2hZCEE2mw.png" /></figure><h3>My Notes</h3><p>Designing shipping form with Tailwind is efficient, and it help the UI developers to be able to customise the layout and design without leaving the html template. By writing classes, we can develop the UI implementation as we wished. Meanwhile, Google Places API is also very useful to create autocomplete form. With Google Places API, we can implement in our site any autocomplete input field that give suggestion when the users start typing. It will definitely help the users to fill the form easily. The documentation provided by Google is also pretty straightforward. The developers just need to utilize it and they already implement autocomplete address.</p><p>Thank you for reading this article. I hope you can enjoy it and can be a helpful resource for your learning process.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14cb83cdc659" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/building-a-localised-places-autocomplete-with-vue-js-tailwind-and-google-places-api-part-1-14cb83cdc659">Building A Localised Places Autocomplete with Vue.js, Tailwind, and Google Places API</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a User Registration and Login with VUE and Firebase Auth]]></title>
            <link>https://medium.com/geekculture/building-a-user-registration-and-login-with-vue-and-firebase-auth-8c6612d9f45e?source=rss-50e42dc3020a------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c6612d9f45e</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[Lughni Alfadjri]]></dc:creator>
            <pubDate>Mon, 24 May 2021 09:30:56 GMT</pubDate>
            <atom:updated>2021-05-31T11:34:54.932Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n7TCP4RKdm8yfSBe6jzJIw.png" /></figure><p>Registration and sign in process is one of the most important features in almost every digital platforms. It is so important that any E-commerces or SAAS platforms generally use registration as one of their KPIs. <strong>In this article, I would like to share my experience in building user registration and login with Vue and Firebase.</strong></p><p>To build user registration and login with Vue and Firebase, there are two main perquisites:</p><ol><li>Vue</li><li>Firebase</li></ol><p>We will build this step by step, so that we can get better insight how the registration and login are implemented with Vue and Firebase.</p><blockquote>You can see the live demo <a href="https://project-real-2d9d9.web.app/"><strong>here</strong></a> and the source code in <a href="https://github.com/Lughnizaid/Registration"><strong>Github</strong></a>.</blockquote><h3>Build Vue Project</h3><p>First, you need to build a Vue Project. To build A Vue Project, you can use Vue CLI. To install it in your system, we can use this command:</p><pre>npm install -g @vue/cli</pre><p>Now, using Vue CLI, youcan use Vue Create to create a Vue project with this command:</p><pre>vue create project-x </pre><p>After creating a Vue Project, you need to run your vue project and see it in your local using this command</p><pre>npm run serve</pre><p>When running the local server is started, you can open your browser to localhost:8080. You should see this by default:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QgKq-V9nFLG2vERjBeDnPg.png" /></figure><p>Perfect!. Now you are done in creatinga Vue Project. Now you can continue by creating a Firebase project.</p><h3><strong>Create a Firebase Project</strong></h3><p>The following step is to create a project in your Firebase console. I assume that you already have firebase account. Click the button to add a new project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*X2rvMQNGPEmVx3b6YgV96A.png" /></figure><p>After Firebase project has been created, you will need to add Firebase to your app. As this article is specifically for web application, click the web icon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*MzXifV9Xcm5N_iTs4H6qwA.png" /></figure><p>Perfect!. Now you need to set the authentication system in Firebase. In this article, there will be 2 main methods in registration and login: Email and Google. Enable the authentication system in Email and Google section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*Bu327Ag8NcD0mOBt0bXzbg.png" /></figure><p>Once Email and Google methods are enabled, the next step will be integrating your Firebase project into Vue project that you created.</p><h3><strong>Integrating Firebase in Vue Project</strong></h3><p>To integrate your Firebase project, you need to insert the firebase ID and configuration detail into your main.js file. You can find the Firebase ID and configuration in your Firebase settings.</p><pre>import Vue from &#39;vue&#39;</pre><pre>import App from &#39;./App.vue&#39;</pre><pre>import router from &#39;./router&#39;</pre><pre>import firebase from &quot;firebase/app&quot;;</pre><pre>var firebaseConfig = {</pre><pre>apiKey: &quot;Firebase data&quot;,</pre><pre>authDomain: &quot;Firebase data&quot;,</pre><pre>projectId: &quot;Firebase data&quot;,</pre><pre>storageBucket: &quot;Firebase data&quot;,</pre><pre>messagingSenderId: &quot;Firebase data&quot;,</pre><pre>appId: &quot;Firebase data&quot;,</pre><pre>measurementId: &quot;Firebase data&quot;</pre><pre>};</pre><pre><em>// Initialize Firebase</em></pre><pre>firebase.initializeApp(firebaseConfig);</pre><pre>Vue.config.productionTip = false</pre><pre>new Vue({</pre><pre>router,</pre><pre>render: <em>h</em> =&gt; h(App)</pre><pre>}).$mount(&#39;#app&#39;)</pre><p>After finishing the integration, it is the time to create the registration and login page in our Vue Project</p><h3><strong>Creating Registration and Login Page</strong></h3><p>Before creating registration and Login page, let’s create a navigation where users can go to other link back and forth.</p><pre>&lt;template&gt;</pre><pre> &lt;div id=&quot;app&quot;&gt;</pre><pre>  &lt;div class=&quot;bar&quot;&gt;</pre><pre>   &lt;router-link to=&quot;/&quot; class=&quot;project&quot;&gt;Project X&lt;/router-link&gt;</pre><pre>   &lt;div class=&quot;nav&quot;&gt;</pre><pre>    &lt;p class=&quot;email&quot; v-if=&quot;auth === true&quot;&gt;{{email}}&lt;/p&gt;</pre><pre>    &lt;router-link  v-if=&quot;auth === false&quot; to=&quot;/register&quot;              <br>    class=&quot;register&quot;&gt;Register&lt;/router-link&gt;</pre><pre>    &lt;router-link v-if=&quot;auth === false&quot; to=&quot;/login&quot;     <br>    class=&quot;login&quot;&gt;Login&lt;/router-link&gt;</pre><pre>    &lt;p v-if=&quot;auth === true&quot; @click=&quot;logout&quot; class=&quot;register&quot;&gt;Log  <br>    out&lt;/p&gt;</pre><pre>  &lt;/div&gt;</pre><pre> &lt;/div&gt;</pre><pre> &lt;router-view&gt;&lt;/router-view&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;/template&gt;</pre><p>In the code above, I create 4 conditionals. The first is for email, if the user already register or sign in, it will display the email. The second one is for register, if the user already login, the register button will not be there. Same with the third conditionals, when the user is already logged in, the login button will not be there. The last conditionals is for logout, if the user is not login, the log out button will not be there.</p><p>Back to the navigation, using router-link, you can redirect to any page in your vue project. Here, you can make the navigation to registration and log in page when the buttons is clicked.</p><p>Once it is finished, you need to set the routing in your router section. You can find index.js file inside of the router folder.</p><pre>const routes = [</pre><pre> {</pre><pre>   path: &#39;/&#39;,</pre><pre>   name: &#39;Home&#39;,</pre><pre>   component: Home</pre><pre> },</pre><pre> {</pre><pre>   path: &#39;/register&#39;,</pre><pre>   name: &#39;Register&#39;,</pre><pre>   component: () =&gt; import(<em>/* webpackChunkName: &quot;about&quot; */</em> <br>   &#39;../views/Register.vue&#39;)</pre><pre> },</pre><pre> {</pre><pre>   path: &#39;/login&#39;,</pre><pre>   name: &#39;Login&#39;,</pre><pre>   component: () =&gt; import(<em>/* webpackChunkName: &quot;about&quot; */</em> <br>   &#39;../views/Login.vue&#39;)</pre><pre>  },</pre><pre>]</pre><p>The code above shows that the path /register and /login will make the users go to the page of register and login.</p><p>To understand better about router-link, you can open this documentation <a href="https://router.vuejs.org/guide/"><strong>https://router.vuejs.org/guide/</strong></a></p><h3><strong>Registration Page</strong></h3><p>I am glad that you finally on this phase!. Lets create registration page.</p><pre>&lt;div class=&quot;google&quot;&gt;</pre><pre> &lt;div class=&quot;google-button&quot; @click=&quot;socialLogin&quot;&gt;</pre><pre>  &lt;img class=&quot;google-icon&quot; href=&quot;#&quot; src=&quot;@/assets/googleicon.png&quot;  <br>  alt=&quot;Image alt&quot;/&gt;</pre><pre>  &lt;a class=&quot;google-word&quot;&gt;Continue with Google&lt;/a&gt;</pre><pre> &lt;/div&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;p&gt;OR&lt;/p&gt;</pre><pre>&lt;form @submit.prevent=&quot;register&quot; class=&quot;register-child&quot;&gt;</pre><pre> &lt;input</pre><pre>  type=&quot;email&quot;</pre><pre>  placeholder=&quot;Email address...&quot;</pre><pre>  v-model=&quot;email&quot;</pre><pre> /&gt;</pre><pre> &lt;input</pre><pre>  type=&quot;password&quot;</pre><pre>  placeholder=&quot;password...&quot;</pre><pre>  v-model=&quot;password&quot;</pre><pre> /&gt;</pre><pre> &lt;button type=&quot;submit&quot;&gt;Register&lt;/button&gt;</pre><pre>&lt;/form&gt;</pre><p>There are two methods of registration page. The first is using Google and the second one is using email. There are two events there which are @click=”socialLogin” and @submit.prevent=”register”.</p><p>In the form section, you put two input, which are email and password. When the register button is clicked, it will activate the certain function named “register”. Same with the registration with Google, in which the certain function named “socialLogin” will be called.</p><p>The next steps will be creating methods to implement registration in with Google and Email.</p><pre>methods: {</pre><pre> register() {</pre><pre>  firebase</pre><pre>   .auth()</pre><pre>   .createUserWithEmailAndPassword(this.email, this.password)</pre><pre>   .then(() =&gt; {</pre><pre>     this.$router.push(&#39;/&#39;);</pre><pre>   })</pre><pre>   .catch(<em>error</em> =&gt; {</pre><pre>     alert(error.message);</pre><pre>   });</pre><pre> },</pre><pre> socialLogin() {</pre><pre>  const provider = new firebase.auth.GoogleAuthProvider();</pre><pre>  firebase.auth().signInWithPopup(provider).then((<em>result</em>) =&gt; {</pre><pre>    this.$router.push(&#39;/&#39;);</pre><pre>  }).catch((<em>err</em>) =&gt; {</pre><pre>    alert(&#39;Oops. &#39; + err.message)</pre><pre>  });</pre><pre> }</pre><pre>},</pre><p>You can find a complete Firebase documentation of doing registration<strong> </strong><a href="https://firebase.google.com/docs/reference/js/firebase.auth.Auth#createuserwithemailandpassword"><strong>here</strong></a><strong> </strong>and for<strong> </strong><a href="https://firebase.google.com/docs/auth/web/google-signin"><strong>Google here</strong></a><strong>. </strong>In the code above, when the user finish registering, either using Email or Google, the user will be redirected to the home page (/).</p><p>Different with registering with Email and Password, any social login is always “sign in” process. Therefore, there are no sign up process using social login Ex: Google authorization in Firebase. Any process is “Sign in”. Therefore the developer can reuse the code either in registration and login page.</p><p>You finish with registration page. Lets continue to build Login functionality in login page.</p><h3><strong>Login Page</strong></h3><p>Lets create the login element in our login page.</p><pre>&lt;div class=&quot;google&quot;&gt;</pre><pre> &lt;div class=&quot;google-button&quot; @click=&quot;socialLogin&quot;&gt;</pre><pre>   &lt;img class=&quot;google-icon&quot; href=&quot;#&quot; src=&quot;@/assets/googleicon.png&quot;  <br>  alt=&quot;Image alt&quot;/&gt;</pre><pre>   &lt;a class=&quot;google-word&quot;&gt;Continue with Google&lt;/a&gt;</pre><pre>  &lt;/div&gt;</pre><pre> &lt;/div&gt;</pre><pre>&lt;p&gt;OR&lt;/p&gt;</pre><pre>&lt;form @submit.prevent=&quot;login&quot; class=&quot;login-child&quot;&gt;</pre><pre> &lt;input</pre><pre>  type=&quot;email&quot;</pre><pre>  placeholder=&quot;Email address...&quot;</pre><pre>  v-model=&quot;email&quot;</pre><pre> /&gt;</pre><pre> &lt;input</pre><pre>  type=&quot;password&quot;</pre><pre>  placeholder=&quot;password...&quot;</pre><pre>  v-model=&quot;password&quot;</pre><pre> /&gt;</pre><pre> &lt;button type=&quot;submit&quot;&gt;Register&lt;/button&gt;</pre><pre>&lt;/form&gt;</pre><p>Same as in registration page, there are two methods of login page. The first is using Google and the second one is using email. There are two events there which are @click=”socialLogin” and @submit.prevent=”login”.</p><p>The next steps will be creating methods to implement the login process with Google and Email.</p><pre>methods: {</pre><pre> login() {</pre><pre>  firebase</pre><pre>  .auth()</pre><pre>  .signInWithEmailAndPassword(this.email, this.password)</pre><pre>  .then(() =&gt; {</pre><pre>   this.$router.push(&#39;/&#39;);</pre><pre>  })</pre><pre>  .catch(<em>error</em> =&gt; {</pre><pre>   alert(error.message);</pre><pre>  });</pre><pre> },</pre><pre> socialLogin() {</pre><pre>  const provider = new firebase.auth.GoogleAuthProvider();</pre><pre>  firebase.auth().signInWithPopup(provider).then((<em>result</em>) =&gt; {</pre><pre>   this.$router.push(&#39;/&#39;);</pre><pre>  }).catch((<em>err</em>) =&gt; {</pre><pre>   alert(&#39;Oops. &#39; + err.message)</pre><pre>  });</pre><pre> }</pre><pre>},</pre><p>The documentation to login with email and password with Firebase, you can find it <a href="https://firebase.google.com/docs/auth/web/password-auth"><strong>here</strong></a><strong>.</strong></p><p>Firebase has different way to have registration and login with Email. In registration, Firebase use “.createUserWithEmailAndPassword(this.email, this.password)” while in sign in process, Firebase uses signInWithEmailAndPassword(this.email, this.password).</p><p>As for social login, the methods is exactly the same because social login in Firebase is always “signin” process.</p><p><strong>After all those steps, finally the registration and login functionality is ready.</strong></p><h3><strong>Conclusion</strong></h3><p>You can see the live demo <a href="https://project-real-2d9d9.web.app/"><strong>here</strong></a><strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uFwrzhrnPdRO8dVkoLYoXw.png" /></figure><p>As for the CSS, because this article is specifically created to build registration and login functionality with Vue and Firebase, you can take a look in the source code displayed in <a href="https://github.com/Lughnizaid/Registration"><strong>Github</strong></a>.</p><h3><strong>My Notes</strong></h3><p>Firebase is very effective way to implement authentication in your platform, either for E-commerce or SAAS. You do not need to write your own backend service as it is already provided by Firebase. In addition, authentication using social account is also popular at the moment, using Firebase will help you to save a lots of time to implement social authentication in your platform.</p><p>I hope you enjoy it. If you like this article, please share it. Thank you for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c6612d9f45e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/building-a-user-registration-and-login-with-vue-and-firebase-auth-8c6612d9f45e">Building a User Registration and Login with VUE and Firebase Auth</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>