<?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 Melika Kalbasi on Medium]]></title>
        <description><![CDATA[Stories by Melika Kalbasi on Medium]]></description>
        <link>https://medium.com/@melikalbasi?source=rss-8f1e79b5ae4f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*xWunQu6k_VBebFOg</url>
            <title>Stories by Melika Kalbasi on Medium</title>
            <link>https://medium.com/@melikalbasi?source=rss-8f1e79b5ae4f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 04:43:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@melikalbasi/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[How to Implement Passport with Google in Your MERN Stack App]]></title>
            <link>https://medium.com/@melikalbasi/how-to-implement-passport-with-google-in-your-mern-stack-app-8c2171717d86?source=rss-8f1e79b5ae4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c2171717d86</guid>
            <category><![CDATA[passport]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[user-authentication]]></category>
            <dc:creator><![CDATA[Melika Kalbasi]]></dc:creator>
            <pubDate>Mon, 11 Feb 2019 23:57:02 GMT</pubDate>
            <atom:updated>2019-02-11T23:57:02.839Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Much easier said than done… until now.</em></p><p>I implemented Passport.js with Google OAuth 2.0 Sign-In Authentication in my most recent project using React and, let me tell you, it was no easy feat. There are many resources out there on the internet that go into detail about the approach you can take to achieving this feature for your application. Though, after further research and many attempts, I discovered that no resource online I found was a “one-stop-shop” in regards to assisting me in my battle to have a simple log-in feature on my site. That’s why I’ve decided to write this blog post, in hopes that it will help the next crazy cat that chooses to use Google OAuth 2.0 with Passport as their form of user authentication. I’ve broken down the steps I took to achieve a successful sign in for my web application, <a href="https://github.com/rhcmoore/root-route">Root Route</a>.</p><p><strong>Step 1: Let’s start with creating your basic React app by entering the following in your command line</strong></p><pre>$ create-react-app name-of-your-app<br>$ cd name-of-your-app<br>$ yarn add react-router-dom<br>$ yarn start</pre><p><strong>Step 2: In App.js in the root directory, add the following HTML code to create a button after the P tag in the render() function. This will give you Google’s fancy sign in button, offering that easy, familiar sign in access for your users.</strong></p><pre>&lt;a href=&quot;/auth/google&quot; class=&quot;button&quot;&gt;<br>          &lt;div&gt;<br>            &lt;span class=&quot;svgIcon t-popup-svg&quot;&gt;<br>              &lt;svg<br>                class=&quot;svgIcon-use&quot;<br>                width=&quot;25&quot;<br>                height=&quot;37&quot;<br>                viewBox=&quot;0 0 25 25&quot;<br>              &gt;<br>                &lt;g fill=&quot;none&quot; fill-rule=&quot;evenodd&quot;&gt;<br>                  &lt;path<br>                    d=&quot;M20.66 12.693c0-.603-.054-1.182-.155-1.738H12.5v3.287h4.575a3.91 3.91 0 0 1-1.697 2.566v2.133h2.747c1.608-1.48 2.535-3.65 2.535-6.24z&quot;<br>                    fill=&quot;#4285F4&quot;<br>                  /&gt;<br>                  &lt;path<br>                    d=&quot;M12.5 21c2.295 0 4.22-.76 5.625-2.06l-2.747-2.132c-.76.51-1.734.81-2.878.81-2.214 0-4.088-1.494-4.756-3.503h-2.84v2.202A8.498 8.498 0 0 0 12.5 21z&quot;<br>                    fill=&quot;#34A853&quot;<br>                  /&gt;<br>                  &lt;path<br>                    d=&quot;M7.744 14.115c-.17-.51-.267-1.055-.267-1.615s.097-1.105.267-1.615V8.683h-2.84A8.488 8.488 0 0 0 4 12.5c0 1.372.328 2.67.904 3.817l2.84-2.202z&quot;<br>                    fill=&quot;#FBBC05&quot;<br>                  /&gt;<br>                  &lt;path<br>                    d=&quot;M12.5 7.38c1.248 0 2.368.43 3.25 1.272l2.437-2.438C16.715 4.842 14.79 4 12.5 4a8.497 8.497 0 0 0-7.596 4.683l2.84 2.202c.668-2.01 2.542-3.504 4.756-3.504z&quot;<br>                    fill=&quot;#EA4335&quot;<br>                  /&gt;<br>                &lt;/g&gt;<br>              &lt;/svg&gt;<br>       &lt;/span&gt;<br>     &lt;span class=&quot;button-label&quot;&gt;Sign in with Google&lt;/span&gt;<br>   &lt;/div&gt;<br>&lt;/a&gt;</pre><p>Note the href linking to “auth/google”. This route will send your user to Google to complete the Gmail authentication. We’ll address the callback in Step 7…</p><p><strong>Step 3: Add these lines of CSS to ensure your button is up to par.</strong></p><pre>a {<br> -webkit-tap-highlight-color: transparent;<br> text-decoration: none;<br>}</pre><pre>.button {<br> display: inline-block;<br> max-width: 300px;<br> margin-top: 50px;<br> border: 0;<br> padding: 0 18px;<br> text-align: left;<br> width: 100%;<br> height: 37px;<br> border-radius: 4px;<br> -webkit-font-smoothing: antialiased;<br> -moz-osx-font-smoothing: grayscale;<br> -moz-font-feature-settings: &quot;liga&quot; on;<br> color: rgba(0, 0, 0, 0.84) !important;<br> fill: rgba(0, 0, 0, 0.84) !important;<br> box-shadow: 0 1px 7px rgba(0, 0, 0, 0.05);<br> font: inherit;<br> outline: none;<br>}</pre><pre>.button .svgIcon {<br> vertical-align: middle;<br> fill: rgba(0, 0, 0, 0.54);<br> padding-right: 4px;<br> height: 37px;<br> display: inline-block;<br>}</pre><p><strong>Step 4: Replace all the text in index.js with the following lines of code.</strong></p><pre>import React from &quot;react&quot;;<br>import ReactDOM from &quot;react-dom&quot;;<br>import &quot;./index.css&quot;;<br>import App from &quot;./App&quot;;<br>import registerServiceWorker from &quot;./registerServiceWorker&quot;;<br>import { Route, Switch } from &quot;react-router-dom&quot;;<br>import { BrowserRouter } from &quot;react-router-dom&quot;;</pre><pre>ReactDOM.render(<br> &lt;BrowserRouter&gt;<br>  &lt;Switch&gt;<br>   &lt;Route path=&quot;/&quot; component={App} /&gt;<br>  &lt;/Switch&gt;<br> &lt;/BrowserRouter&gt;,<br> document.getElementById(&quot;root&quot;)<br>);<br>registerServiceWorker();</pre><p>What we’re doing here is just importing Route, Switch and BrowserRouter from “react-router-dom” and using a React switch statement in the render function to support the routes in our application.</p><p><strong>Step 5: Create a Node.js server in your app and configure Passport.</strong></p><p>At the root of your directory, create a server.js file. Make sure your server is running on a different port than your React app as React is a front end framework and will be running separately from your back end.</p><p>Install Passport in your app by running the following in the command line while in the root of your app:</p><pre>$ yarn add passport<br>$ yarn add passport-google-oauth</pre><p>Now that we’ve installed the required modules, require passport and initialize passport by ensuring your server.js file includes the following:</p><pre>// Requiring necessary packages</pre><pre>var express = require(&quot;express&quot;);</pre><pre>var bodyParser = require(&quot;body-parser&quot;);</pre><pre>// Requiring passport as we&#39;ve configured it</pre><pre>var passport = require(&quot;passport&quot;);</pre><pre>// Setting up port </pre><pre>var PORT = process.env.PORT || 3001;</pre><pre>// Creating express app and configuring middleware needed for authentication</pre><pre>var app = express();</pre><pre>app.use(bodyParser.urlencoded({ extended: false }));</pre><pre>app.use(bodyParser.json());</pre><pre>app.use(express.static(&quot;client/build&quot;));</pre><pre>app.use(passport.initialize()); </pre><pre>require(&quot;./config/passport&quot;);<br></pre><pre>// Syncing our database and logging a message to the user upon success</pre><pre>app.listen(PORT, function() {</pre><pre>console.log(&quot;==&gt; 🌎  Listening on port %s. Visit http://localhost:%s/ in your browser.&quot;, PORT);</pre><pre>});</pre><p>*Make sure you are changing the default server port to be consistent throughout your entire app. As long as it’s not 3000, you’re in the clear. (React always runs on port 3000, we change our server port to avoid conflicts).</p><p><strong>Step 6: Now let’s configure our Passport.js file that will handle our passport authentication mechanisms.</strong></p><p>In your root directory, create a folder titled<em> config</em> and inside that folder, create a file called <em>passport.js. </em>Inside of that file, copy in this code:</p><pre>var passport = require(&quot;passport&quot;);<br>var GoogleStrategy = require(&quot;passport-google-oauth&quot;).OAuth2Strategy;</pre><pre>passport.serializeUser(function(user, done) {<br> done(null, user);<br>});</pre><pre>passport.deserializeUser(function(user, done) {<br> done(null, user);<br>});</pre><pre>passport.use(<br> new GoogleStrategy(<br>  {<br>   clientID: &quot;GOOGLE_CLIENT_ID&quot;,<br>   clientSecret: &quot;GOOGLE_CLIENT_SECRET&quot;,<br>   callbackURL: &quot;http://localhost:3001/auth/google/callback&quot;<br>  },<br>  function(accessToken, refreshToken, profile, done) {<br>   var userData = {<br>    email: profile.emails[0].value,<br>    name: profile.displayName,<br>    token: accessToken<br>   };<br>   done(null, userData);<br>  }<br> )<br>);</pre><p>You’ll notice here that we will be in need of a GOOGLE_CLIENT_ID as well as a GOOGLE_CLIENT_SECRET. This is where <a href="https://console.developers.google.com/">Google Cloud Platform</a> will come into play. Click the link or visit <a href="https://console.developers.google.com/">https://console.developers.google.com/</a> and set your app up with a Client ID and Client Secret there.</p><p><strong>Step 7: Use the Google Cloud Platform to gain access to a Client ID and Client Secret, as well as set up your query params for your verify callback…</strong></p><p>Navigate to the Google Developer’s Console and create your application there. You will then click the <em>Create Credentials</em> button and select <em>OAuth client ID.</em></p><p>In the next screen, select Application type as a <em>Web application </em>and name your application.</p><p>In the Restrictions part, you need to provide your app URL and redirect URL to prevent others misusing your application.</p><p>Provide your app URL as follows in the <em>Authorised JavaScript origins</em>. You can add multiple entries here.</p><blockquote>http://localhost:3001</blockquote><p>Since our server in this example is running in the port 3001. (Allowing server to authenticate)</p><p>Provide your redirect URL as follows in the <em>Authorized Redirect URIs</em>.</p><blockquote>http://localhost:3001/auth/google/callback</blockquote><p>Since we need to redirect back to our server after Google authentication gets completed. (We have also mentioned this URL in our <em>passport.js</em> file)</p><p>Once you’ve been assigned your GOOGLE_CLIENT_ID &amp; GOOGLE_CLIENT_SECRET key, create a .env file and link them in there using the dotenv package. (If it’s just for testing purposes, feel free to just replace those placeholders in your passport.js with your assigned credentials.)</p><p>Finally, click <em>Library</em> which is above <em>Credentials</em> and search for Google+ API. Select and enable to get a user’s Google+ profile.</p><p><strong>Step 8: Set up routes to handle Google authentication</strong></p><p>Now let’s create an API call called /auth/google which our client calls after clicking the <strong>Sign in with Google</strong> button.</p><p>Go to <em>index.js</em> in <em>routes</em> folder and add the following line at the header.</p><pre>var passport = require(“passport”);</pre><p>and below lines after the default get request.</p><pre>/* GET Google Authentication API. */<br>router.get(<br>    &quot;/auth/google&quot;,<br>    passport.authenticate(&quot;google&quot;, { scope: [&quot;profile&quot;, &quot;email&quot;] })<br>);</pre><pre>router.get(<br>    &quot;/auth/google/callback&quot;,<br>    passport.authenticate(&quot;google&quot;, { failureRedirect: &quot;/&quot;, session: false }),<br>    function(req, res) {<br>        var token = req.user.token;<br>        res.redirect(&quot;<a href="http://localhost:3000/?token=">http://localhost:3000?token=</a>&quot; + token);<br>    }<br>);</pre><p>You have now configured your server!</p><p>The above snippet contains the routes to get the request from the client and authenticate through Google using Passport. The client is sent to Google to select their Gmail account they would like to associate with your web application, then Google does the heavy lifting and assigns them a Google OAuth 2.0 token and passes it through the callback, which invokes after the client completes the Google Authentication.</p><p>The passport.js file in your config folder is creating the object for the user and sending it to the callback function. The way we are communicating with Google through Passport is through the <em>serializeUser</em> and <em>deserializeUser</em> functions. These functions are accessing the <em>user </em>part of the Google Strategy we provided in the index.js file and creating a token for each user.</p><p>Finally, we are redirecting our client back to our app which is running in the port 3000 with a token in the query param.</p><p><strong>Step 9: Receive a token and authenticate user</strong></p><p>Install the query-string module to parse through query strings in React</p><pre>$ yarn add query-string</pre><p>Import query-string in your App.js file</p><pre>import queryString from &quot;query-string&quot;;</pre><p>And include the following React Component Lifecycle Method in your file</p><pre>componentDidMount() {<br>    var query = queryString.parse(this.props.location.search);<br>    if (query.token) {<br>      window.localStorage.setItem(&quot;jwt&quot;, query.token);<br>      this.props.history.push(&quot;/&quot;);<br>   }<br>}<br>render(){<br>   ...<br>}</pre><p>This method will get the query param token from the URL during initialization and set it in local storage.</p><p>Now you can replace the token in the callback URL. You will use the token given to authenticate each user and provide it to every request to your API server.</p><p>You have now successfully implemented Passport with Google in your MERN app!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c2171717d86" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Habbit Rabbit, The App That Works You]]></title>
            <link>https://medium.com/@melikalbasi/habbit-rabbit-the-app-that-works-you-ec92788769b1?source=rss-8f1e79b5ae4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec92788769b1</guid>
            <category><![CDATA[food]]></category>
            <dc:creator><![CDATA[Melika Kalbasi]]></dc:creator>
            <pubDate>Wed, 16 Jan 2019 03:24:08 GMT</pubDate>
            <atom:updated>2019-01-16T03:24:57.230Z</atom:updated>
            <content:encoded><![CDATA[<p>Working toward becoming a creature of habit requires a good amount of discipline and drive. The concept of Habbit Rabbit came into fruition based on that idea. We wanted to make things simple by turning that tedious process into a simple app you could turn to while flipping through other various apps on your phone. Our tool helps you build better lifestyle habits, starting with diet and exercise. By providing recipes based on your dietary preference, and exercises based on your capabilities, Habbit Rabbit allows you to have a selection of healthy choices right at your fingertips. The app requires signing up to access all the features, and once you’re in, you can peruse a wide range of recipes and workouts to keep you on track. The app offers easy and delicious recipes that can be made with items that are most likely already in your kitchen, as well as offering exercises and activities you can do in the comfort of your own home. The app welcomes you with little affirmations each time you visit, to keep those positive vibes in mind all day! Visiting this app is something people will want to do, as their little escape from their obligations, and to ensure to squeeze in some “me time” no matter how little time they have for that.</p><p>Creating this app required a MVC paradigm to ensure our users that they’re leaving the busy work to us, and only the fun of our app to them (although can’t say learning countless new recipes to try wasn’t fun). To populate our app with delicious recipes and fun workouts, we decided to create our own API instead of outsourcing for a variety of existing ones. We knew what we wanted to offer our users and felt by taking on the task of developing our database, we could have full control over giving what our users want. We used Handlebars and Sass to create our pages, and doing so allowed our theme to be consistent for easy accessibility of our app. Handlebars was optimal in grabbing data from our tables and appending them to our pages with ease. Sass was utilized to quickly translate our CSS across our pages with the use of variables and nested syntax, making the styling of our application easier to maintain. We used Passport.js for user authentication and manipulated the code to allow for users to include their dietary preference as well as their age in order to initialize personalized tables of recipes and workouts based on their answers. This way, our users don’t need to sift through meat dishes if they’re vegetarian, or couscous recipes if they’re gluten free. We kept our workouts simple based on your age. If you are a senior, we offer a selection of at home exercises that won’t push you too hard, but still keep you in shape, while those below the age of 65 have a variety of workouts that are more accelerated. Our user friendly app is a must have if you are in the market for building better lifestyle habits.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec92788769b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working Towards Becoming a Full Stack Developer and Google-Fu Master]]></title>
            <link>https://medium.com/@melikalbasi/working-towards-becoming-a-full-stack-developer-and-google-fu-master-75f7272c0fb?source=rss-8f1e79b5ae4f------2</link>
            <guid isPermaLink="false">https://medium.com/p/75f7272c0fb</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Melika Kalbasi]]></dc:creator>
            <pubDate>Wed, 05 Dec 2018 04:33:29 GMT</pubDate>
            <atom:updated>2018-12-05T07:06:04.561Z</atom:updated>
            <content:encoded><![CDATA[<p>Probably the hardest thing to relearn while taking a coding bootcamp is exactly that… how to relearn. A big part of being a web developer is figuring things out on your own. While I’ve made it through life this far by asking questions and making astute observations, the primal way of learning to code is figuring it out yourself. By that, professors mean Googling it. Though it may sound simple, this has been a harder concept for me to grasp as I was always led to believe that knowledge you find on the internet is vastly inferior to the knowledge you gather from experience and learning from others. The more I’m utilizing my Google-Fu, the more I’m learning that the internet really has become parallel to what you can find in reality, minus the experience.</p><p>I found through working on my first group project, and taking a concept and bringing it to fruition in the form of an app, was breaking ground for figuring it out on my own. We created a new application called Keeper, designed to assist you in your shopping ventures. Keeper allows for the public to act as your own personal shopper whenever you upload an image. The debate takes place over a simple “Yes” or “No” voting poll. Simplicity and functionality at it’s finest. Until it came to finding a very specific API to be implemented in our app.</p><p>In the midst of our process, we knew we wanted to include an API where our users could identify where an item uploaded was purchased from. After some deep diving into a variety of apparel related API’s and their documentation, we landed on the Google Places API to assist in matching up our uploader’s item with the corresponding store and nearest location to the one inquiring. Initially, we faced a challenge in how we were querying our AJAX call. We couldn’t get a JSON object to return at all (only once did we receive a JSON object and it was for the Museum of Modern Art).</p><p>When at a loss for where to start or what to do next, querying Google with simple terms in the realm of my confusion led us to the right direction. It takes some weaving in and out of forums and tutorials to really refine your findings into applicable code. This skill really came in handy when it came to those trying times when our API calls would return something completely random such as museum results when querying clothing stores…</p><p>A big lesson to be learned here is… do not simply copy and paste code you find online, even if it is within the documentation of the API. Sometimes you need to play around in your console to find the answer and trust your ability to code your way through. After enough practice in Google-Fu, you come to realize that part of what it means to “Fu” is to take bits and pieces of what you’ve gathered in research, and divvy snippets of code to come up with a solution to your unique issue. Though you might find in very rare (but beautiful) cases, that someone that was once in the same predicament as you and got their question answered on StackOverflow.</p><p>View the Keeper app on your mobile or desktop device here: <a href="https://melikalbasi.github.io/Keeper_App/">https://melikalbasi.github.io/Keeper_App/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75f7272c0fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>