<?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: Ekama Emmanuel </title>
    <description>The latest articles on DEV Community by Ekama Emmanuel  (@ekamanelly).</description>
    <link>https://dev.to/ekamanelly</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%2F687867%2F7114b626-71a0-4c6b-bfa8-a09a64a2e59c.jpeg</url>
      <title>DEV Community: Ekama Emmanuel </title>
      <link>https://dev.to/ekamanelly</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ekamanelly"/>
    <language>en</language>
    <item>
      <title>Welcome to Hotel VPC at AWS</title>
      <dc:creator>Ekama Emmanuel </dc:creator>
      <pubDate>Wed, 24 Aug 2022 06:30:00 +0000</pubDate>
      <link>https://dev.to/ekamanelly/welcome-to-hotel-vpc-at-aws-14d8</link>
      <guid>https://dev.to/ekamanelly/welcome-to-hotel-vpc-at-aws-14d8</guid>
      <description>&lt;p&gt;I am very excited to be your host and at the same time your tour guide. You are welcome to the VPC hotel here at AWS. In view is a map to visually aid our imagination and guide us during the course of this trip.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r7Y0pLK1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ro7df2brgn7us8s2crba.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r7Y0pLK1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ro7df2brgn7us8s2crba.jpeg" alt="Image description" width="880" height="878"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let me start by showing you how to find your way around in case of any unforeseen incidence. First and foremost, we have two sections here at this VPC and we refer to them as &lt;strong&gt;AZ&lt;/strong&gt;. On your way here you passed the very secure gate, Aws staffs calls it &lt;strong&gt;IGW&lt;/strong&gt;, but I prefer the full name &lt;strong&gt;&lt;em&gt;internet Gateway&lt;/em&gt;&lt;/strong&gt;. The strength of the &lt;strong&gt;IGW&lt;/strong&gt; is what we bank on and it's the only way in or out of this VPC. Only authorized users can access it and you can see it's location on the map.&lt;/p&gt;

&lt;p&gt;Moving on, is the receptionist office, there will see a nice lady who's an expert in multitasking and she also makes sure no department is over worked. No AWS staff knows her by her real name so we call her by her nature, &lt;strong&gt;Load Balancer&lt;/strong&gt; or LB for short. She has two offices in this branch, one of them is where we'll be visiting next and the other one she only uses when something goes wrong is this AZ. She swiftly changes her office to get all staffs back on track and controls the chaos. Much Later, I will share more details on her role and why we appreciate her job. You can see her offices on the map too.&lt;/p&gt;

&lt;p&gt;I forgot to mention we refer to rooms or offices as &lt;strong&gt;SubNet&lt;/strong&gt;. We go the length to localize the experience. So public offices that have less restriction are called &lt;strong&gt;Public Subnets&lt;/strong&gt; and restricted ones are called? You guessed it, &lt;strong&gt;Private Subnet&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;When LB clears us, we should have a &lt;strong&gt;Subnet&lt;/strong&gt; and a luggage boy to take us there. I must warn you about luggage boys, they have very strict policies to follow instructions given to them by LB in one heavily protected note. They'll raise the note and yell &lt;strong&gt;Route Rule&lt;/strong&gt;! &lt;strong&gt;Route Rule&lt;/strong&gt;! Whenever you try to tip them to change course. Even I can't make them change their course. Dumb and loyal and I just called them &lt;strong&gt;Route&lt;/strong&gt;! They will take us to our allocated &lt;strong&gt;Private Subnet&lt;/strong&gt; without fail.&lt;/p&gt;

&lt;p&gt;Hopefully, you will like your &lt;strong&gt;subnet&lt;/strong&gt;, But if you don't, you have the privilege to do as you please. The room comes with a basic plan and it's completely free for a year, but you can satisfy your curiosity and possibly customize your &lt;strong&gt;subnet&lt;/strong&gt;. Please check the &lt;strong&gt;instances list&lt;/strong&gt; to see your options. Myself and staffs calls the options &lt;strong&gt;EC2&lt;/strong&gt;, which is &lt;strong&gt;Elastic compute cloud&lt;/strong&gt; in full. You have flavor of Windows, Linux and even the latest Mac2...&lt;/p&gt;

&lt;p&gt;I must spill! Scott Malkie, Farrah Campbell and Steve showcased its features just last week. So if you are going to do some heavy lifting, this &lt;strong&gt;VPC&lt;/strong&gt; have you covered. Whatever option you eventually go with, it only takes some few minutes to set up by our &lt;strong&gt;Launch Configuration&lt;/strong&gt; department. &lt;/p&gt;

&lt;p&gt;When you are settled in your customize Ec2 instance and you feel like stepping out, you can call the &lt;strong&gt;Route&lt;/strong&gt; boy. They would take you through a different hallway, much different from the one you took to your &lt;strong&gt;Private subnet&lt;/strong&gt;. This &lt;strong&gt;VPC&lt;/strong&gt; Have a special requirement for those lodging in &lt;strong&gt;Private subnet&lt;/strong&gt;. You are our top priority customer and is a must, you drop your &lt;strong&gt;EIP&lt;/strong&gt; keys with Mr &lt;strong&gt;NAT&lt;/strong&gt; before leaving your &lt;strong&gt;Private Subnet&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Mr &lt;strong&gt;NAT&lt;/strong&gt;'s office, Sorry, I meant &lt;strong&gt;"subnet"&lt;/strong&gt; is also on the map. NAT is just and acronym of his name &lt;strong&gt;Network address translator&lt;/strong&gt;. If it wasn't for unfair company's politics, I should be in charge of his &lt;strong&gt;subnet&lt;/strong&gt;. Please be careful with him, it's one way with him. &lt;/p&gt;

&lt;p&gt;So, back to Lb, Who is my favorite person in this hotel, actually she is everyone's favorite. For each customizable subnet you decide to go with, she keeps an exact replica in the other AZ where her second office is located. So maybe your room gets flooded or have a power failure. Although, these sorts of things rarely happens, she works with &lt;strong&gt;launch Configuration&lt;/strong&gt; and &lt;strong&gt;Auto Scaling&lt;/strong&gt; department to make sure you have a spare room and a very smooth transition to the other AZ. Enough about LB before you start questioning my emphasis.&lt;/p&gt;

&lt;p&gt;Before I let you go, There is a tiny note that would be given to you, it's called &lt;strong&gt;Route Table&lt;/strong&gt;. It contains all the places you can possibly visit within this &lt;strong&gt;AZ&lt;/strong&gt;. You can call the &lt;strong&gt;Route boy&lt;/strong&gt; to take you to anyone... You are allowed to add more exciting places. Feel free to call the &lt;strong&gt;Security Groups&lt;/strong&gt; department to help you with that. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here are keynote you should remember&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mrs LB two offices, in case of any incident&lt;/li&gt;
&lt;li&gt;Don't tip the Route boys. Route boys, the Security Group and the Route Rules work in a mix to keep us secured within this VPC.&lt;/li&gt;
&lt;li&gt;Offices are public subnet, rooms are private subnet and section are AZ (Availability Zone)&lt;/li&gt;
&lt;li&gt;EIP is your key to leave your subnet &lt;/li&gt;
&lt;li&gt;You use Mr NAT Public Subnet before leaving and remember to drop your keys&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Hope you have a nice time here at AWS VPC.
&lt;/h2&gt;

</description>
    </item>
    <item>
      <title>Google oAuth on NextJs</title>
      <dc:creator>Ekama Emmanuel </dc:creator>
      <pubDate>Wed, 24 Nov 2021 10:35:20 +0000</pubDate>
      <link>https://dev.to/ekamanelly/google-oauth-on-nextjs-3ml5</link>
      <guid>https://dev.to/ekamanelly/google-oauth-on-nextjs-3ml5</guid>
      <description>&lt;p&gt;If your search has brought you here, then I'm sure you have done some type of authentication and authorization with probably Express &lt;a href="https://www.npmjs.com/package/passport"&gt;PassportJs&lt;/a&gt; on a project, so Let's save our time by jumping to straight to bullet overview and implementation.&lt;/p&gt;

&lt;h6&gt;
  
  
  Overview
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;Add NextJs app to Google console &lt;/li&gt;
&lt;li&gt;Configure NextJs app with firebaseConfig (some few changes with firebase v9.0.0)&lt;/li&gt;
&lt;li&gt;Employ environment variable to hold secret
&lt;/li&gt;
&lt;li&gt;Build an auth-Service&lt;/li&gt;
&lt;li&gt;Protected routes with custom hooks
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Adding your Next app to Google console is pretty easy, It's like when you deploy on Varcel, with some few clicks you are done! You have a dashboard that gives a brief overview of your project when you create a project on google console. click on "Add app" button at the top and you will be taken to this page to provide a nickname for your app, mine is MetaApp. Then, follow the next few steps, it is self explanatory. Don't forget to copy firebaseConfig!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ocI3l7cL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5czqcvz2k1vxpl7t1bfp.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ocI3l7cL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5czqcvz2k1vxpl7t1bfp.PNG" alt="Register app" width="768" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you're through with app registration, let's make use of the snippet you copied. Create a file with a name related to firebase, something like &lt;code&gt;fireBaseClient.js&lt;/code&gt; in a Service Folder and then import firebase app and auth.  *&lt;em&gt;side note **We import app and auth from *firebase/compact/&lt;/em&gt; not  &lt;em&gt;firebase/&lt;/em&gt; since Version 9 like so&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// service/fireBaseClient.js

import firebase from "firebase/compat/app";    firebase v9
import "firebase/compat/auth";                 firebase V9
import "firebase/compat/firestore";            firebase V9

// import firebase from "firebase/app";         firebase v8 
// import "firebase/auth";                      firebase v8 
// import "firebase/firestore";                 firebase v8 



const firebaseConfig = {
  apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
  authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
  projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
  storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
  messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
  appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
  measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,
};
if (!firebase.apps.length) {
  firebase.initializeApp(firebaseConfig);
}
export default firebase;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You noticed how we hid the secret keys with environment variable? yeah, it's possible with NextJs. All I did was add an &lt;code&gt;env.local&lt;/code&gt; file to the root directory and paste the secret. Another &lt;strong&gt;side note&lt;/strong&gt; is that each env variable should start with &lt;code&gt;NEXT_PUBLIC_&lt;/code&gt; with whatever you chose to complete the name. It's how Next.js gets to know what to load or bundle. Also, there are trailing commas &lt;code&gt;,&lt;/code&gt; that came with the code we copied, get rid of them. I lost a couple hours debugging them. Once that is done we don't have to worry about our secret getting stolen by village people, haha! Quick example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NEXT_PUBLIC_SOMENAME = "MetaAppSecrete"
// don't forget the comma
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will also see a condition &lt;code&gt;!firebase.apps.length&lt;/code&gt;,  this is to make sure we don't initialize another firebase app. Now we have completed firebase setup. It's time to build a signUpWithGoogle service&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;service/firebaseAuth.service.js

import firebase from "firebase/compat/app";
import "firebase/compat/auth";

export const  AuthService = {}

AuthService.loginWithGoogle = async () =&amp;gt; {
  const provider = new firebase.auth.GoogleAuthProvider();
  try {
    const { user } = await firebase.auth().signInWithPopup(provider);
    return {
      user,
    };
  } catch (error) {
    return {
      error: error.message,
    };
  }
};


AuthService.logout = async () =&amp;gt; {
  await firebase.auth().signOut();
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Honestly, I feel like there is no need explaining the code because you might shoplift it, which in my opinion, is the best technique of coding fast with &lt;a href="https://stackoverflow.com"&gt;StackOverflow&lt;/a&gt;. But let me explain, google gives us a provider when we execute this &lt;code&gt;new firebase.auth.GoogleAuthProvider()&lt;/code&gt; and we will call the type of login method we want on the provider, in our case it's &lt;code&gt;signInWithPopup&lt;/code&gt; type. There are others that redirects the user but I prefer the popup.&lt;/p&gt;

&lt;p&gt;Finally, we can tie our loginWithGoogle function to a signup button with an &lt;code&gt;onClick&lt;/code&gt; event. You don't need a snippet for this, do you?  &lt;/p&gt;

&lt;p&gt;This  post is becoming too long so I will deal with route protection in as a separate post.   &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
