<?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 Gaetandelsaux on Medium]]></title>
        <description><![CDATA[Stories by Gaetandelsaux on Medium]]></description>
        <link>https://medium.com/@gaetandelsaux?source=rss-96f95ced8e19------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*peFfk8wL0cq8DA2CCJwLBg.jpeg</url>
            <title>Stories by Gaetandelsaux on Medium</title>
            <link>https://medium.com/@gaetandelsaux?source=rss-96f95ced8e19------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 09:15:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gaetandelsaux/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[Setting Up Google Authentication in Next.js: A Developer’s Guide]]></title>
            <link>https://medium.com/@gaetandelsaux/setting-up-google-authentication-in-next-js-a-developers-guide-6a6e0f16b18f?source=rss-96f95ced8e19------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a6e0f16b18f</guid>
            <category><![CDATA[google]]></category>
            <category><![CDATA[nextjs-tutorial]]></category>
            <category><![CDATA[nextauth]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Gaetandelsaux]]></dc:creator>
            <pubDate>Fri, 10 Jan 2025 12:58:50 GMT</pubDate>
            <atom:updated>2025-01-10T12:58:50.845Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*IiXEi5C9taySv68kyoSv6Q.png" /></figure><p>Authentication is a cornerstone of modern web applications. With services like Google offering secure OAuth2 mechanisms, integrating them into frameworks like Next.js is both powerful and practical. This article walks you through the process of setting up Google Authentication in your Next.js application using NextAuth.js.</p><h3>Prerequisite</h3><ul><li>An existing NextJs app (v15)</li><li><strong>NextAuth.js installed</strong>, you can refer to the official documentation <a href="https://next-auth.js.org/getting-started/example">here</a>.</li><li><strong>Server Actions enabled in Next.js</strong>:</li></ul><pre>/** @type {import(&#39;next&#39;).NextConfig} */<br>const nextConfig = {<br>  experimental: {<br>    serverActions: true, // Enable server actions<br>  },<br>};<br><br>module.exports = nextConfig;</pre><h3>Step 1: Create an OAuth Client ID</h3><p>Head over to Google Cloud Console and follow these steps:</p><ol><li><strong>Create a new project</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*0bXJzi8_iGfHAPML-XjXfQ.png" /></figure><p>The name doesn’t matter but use a name that makes sense to you</p><p><strong>2. Configure your project</strong></p><p>In <strong>App Information, </strong>here the app name name is important this is the name that will be displayed to your users on the google sign in card where they will put the credentials. You also need to put an email for people to contact you for support</p><p>In <strong>Audience</strong>, choose between <strong>Internal</strong> or <strong>External</strong>, use the info provided to make your choice.</p><p>In <strong>Contact Information, </strong>re-enter your email.</p><p>In <strong>Finish, </strong>accept the Ts&amp;Cs and press create</p><p><strong>3. Create OAuth client ID</strong></p><p>Click on <strong>Overview</strong> on the left-hand side menu, in the first drop-down choose <strong>Web application</strong></p><p>Choose a name for your OAuth client ID</p><p>For <strong>Authorized JavaScript origins</strong> click on ADD URI. Put <a href="http://localhost:3000/">http://localhost:3000</a></p><p>For <strong>Authorized redirect URIs</strong> click on ADD URI again. Put <a href="http://localhost:3000/">http://localhost:3000</a>/api/auth/callback/google</p><p>Press <strong>Create</strong></p><p>It’s important to note that you should you use port that your nextjs app run on if it isn’t the default one.</p><p>In a production environment you would also need to add an ‘s’ at the end of http and replace all instances of localhost with your domain name!</p><p>Your can find more details <a href="https://next-auth.js.org/providers/google">here</a></p><p><strong>4. Get your Client ID</strong></p><p>Click on the download button (right-hand size of the row) to see your client ID and make a note of C<strong>lient ID </strong>and <strong>Client secret.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6brOBrSfPmPFOWjuZCfUYQ.png" /></figure><h3>Step 2: Configure Authentication</h3><p>This tutorial focuses on Google Authentication, but you can configure multiple providers. Refer to the <a href="https://next-auth.js.org/providers/">NextAuth.js Providers documentation</a> for more details.</p><p><strong>1. Create the Authentication Configuration</strong></p><p>Create a new file, for example: lib/auth.ts, and add the necessary configuration.</p><pre>import { NextAuthOptions } from &#39;next-auth&#39;<br>import GoogleProvider from &#39;next-auth/providers/google&#39;<br><br>export const authConfig: NextAuthOptions = {<br>    providers: [<br>        GoogleProvider({<br>            clientId: process.env.GOOGLE_CLIENT_ID as string,<br>            clientSecret: process.env.GOOGLE_CLIENT_SECRET as string<br>        })<br>    ]<br>}</pre><h4>Define the Auth Route</h4><p>Set up the NextAuth API route as follows:</p><ol><li><strong>Create the route for auth:</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/248/1*78fbh2swwtzOFa3VikT8-w.png" /></figure><p><strong>2. Your route.ts will be as follow:</strong></p><pre>import { authConfig } from &#39;@/lib/auth&#39;<br>import NextAuth from &#39;next-auth/next&#39;<br><br>const handler = NextAuth(authConfig)<br><br>export { handler as GET, handler as POST}</pre><h3>Step 3: Manage Sessions</h3><h4>Get the Session</h4><p>To retrieve the session, create a server action, for example: server/actions/getSession.ts.</p><pre>&#39;use server&#39;<br>import { getServerSession } from &quot;next-auth&quot;<br>import { Session } from &quot;next-auth&quot;<br><br>export const getSession = async (): Promise&lt;Session | null&gt; =&gt; {<br>    const session = await getServerSession()<br><br>    return session<br>}</pre><h4>Sign Out</h4><p>To log the user out, we’ll utilize the built-in signout.</p><h3>Step 4: Final piece of code</h3><p>Open your main page.tsx, your code will be as follow:</p><pre>&#39;use client&#39;<br>import { redirect } from &quot;next/navigation&quot;;<br>import { getSession } from &quot;@/server/actions/getSession&quot;;<br>import { useEffect, useState } from &quot;react&quot;;<br>import { Session } from &quot;next-auth&quot;;<br>import Image from &quot;next/image&quot;;<br>import { signOut } from &quot;next-auth/react&quot;;<br><br>export default function Home() {<br>  const [session, setSession] = useState&lt;Session | null&gt;(null)<br>  useEffect(() =&gt; {<br>    const getServerSession = async () =&gt; {<br>      const session = await getSession()<br>      if (!session) redirect(&#39;/api/auth/signin&#39;)<br>      setSession(session)<br>    }<br>    getServerSession()<br>  }, [])<br><br><br>  return (<br>    &lt;div className=&quot;flex flex-col column items-center align-center justify-center min-h-screen p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]&quot;&gt;<br>      &lt;p&gt;Hello {session?.user?.name}&lt;/p&gt;<br>      {<br>        session?.user?.image &amp;&amp;<br>        &lt;Image <br>          src={session?.user?.image}<br>          width={40}<br>          height={40}<br>          alt=&quot;profile image&quot;<br>          className=&quot;rounded-full&quot;<br>        /&gt;<br>      }<br>      &lt;p&gt;{session?.user?.email}&lt;/p&gt;<br>      &lt;button className=&quot;rounded-lg border border-slate-300 hover:border-slate-400 px-2 py-1&quot; onClick={() =&gt; signOut()}&gt;Sign Out&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br></pre><p>Let’s break it down a little here.</p><ol><li>In our useEffectwe use our server action to get the session token.</li><li>If no session is present we redirect to /api/auth/signin, our login page, the google sign in button in this case.</li><li>If a session token is found we assign it to our session state and render the details on screen</li></ol><h4>note:</h4><p>If you intend to use the next/image component, ensure your next.config.js includes the domain used by Google for profile pictures:</p><pre>/** @type {import(&#39;next&#39;).NextConfig} */<br><br>const nextConfig = {<br>  experimental: {<br>    serverActions: true, // Enable server actions<br>  },<br>  images: {<br>    domains: [&#39;lh3.googleusercontent.com&#39;],<br>  },<br>};<br><br>module.exports = nextConfig;</pre><h3>Final Thoughts</h3><p>With these steps, you’ve set up a robust Google Authentication mechanism in your Next.js application. NextAuth.js simplifies the process, allowing developers to focus more on building features and less on managing authentication complexities.</p><p>If you found this tutorial helpful, feel free to share it with your peers or leave your thoughts in the comments section!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a6e0f16b18f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Set up EmailJs in React app from scratch.]]></title>
            <link>https://blog.devgenius.io/set-up-emailjs-in-react-app-from-scratch-42e669efc22a?source=rss-96f95ced8e19------2</link>
            <guid isPermaLink="false">https://medium.com/p/42e669efc22a</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[email]]></category>
            <category><![CDATA[emailjs]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Gaetandelsaux]]></dc:creator>
            <pubDate>Thu, 10 Mar 2022 00:27:43 GMT</pubDate>
            <atom:updated>2022-04-14T14:47:52.700Z</atom:updated>
            <content:encoded><![CDATA[<h3>EmailJs in your React app from scratch.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ThrwevcjaDOmEVPgPYIgTg.png" /></figure><p>Before going into the hows of the implementation, let’s identify what EmailJs is. <a href="https://www.emailjs.com/">EmailJ</a>s is a platform that allows you to send and receive emails without using a backend. The platform has a friendly user interface from which you can easily create email templates with dynamic parameters.</p><p>You can use various ways to set up EmailJs in your React app; this article will focus solely on EmailJs installed as a dependency.</p><h3>Use create-react-app</h3><p>What is create-react-app? Simply put, it creates a boilerplate React app without needing any configuration from us, which means we can start working on your project right away 🙌.</p><p>Now it’s time to open up our terminal and create our app; when this is done, type the following command:</p><pre>npx create-react-app your-app <strong>//if you use npm</strong><br>yarn creat react-app your-app <strong>//if you use yarn</strong></pre><p>Whist our terminal is opened, cd into the app folder, then go ahead and install the following package:</p><pre>cd your-app<br>npm install emailjs-com <strong>//if you use npm<br></strong>yarn add emailjs-com <strong>//if you use yarn</strong></pre><p>Next up, open the app directory in your IDE of choice; I prefer Visual Studio Code. Your directory should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*MBYHVP6B2GgMhWV6N97IxQ.png" /></figure><p>Feels free to explore this directory, especially the README.md file; it’s packed with helpful information. The only file that interests us at the moment is app.js in the src folder, let’s open it and remove all the unnecessary code from it; you should end up with the code below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*ZL1YyaI27FocKZ8L5oqKmw.png" /></figure><p>That’s it for our React app set-up. Next, we will dive into EmailJs’ implementation and how to create email templates 🙂.</p><h3>Get started with EmailJs.</h3><h4>Create an account</h4><p>First, we will need to create an account on <a href="https://www.emailjs.com/">EmailJs’</a> website; once done, we will need to confirm our email, and we’re ready for the next step.</p><p>After login in, you should land on the following page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AbHPnSebSrTOIzhdFNcijw.png" /></figure><p>Next, click on Add New Service and select your email client of choice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3FSuZkPMm8kdWtS4mlJV7g.png" /></figure><p>From here, click on Connect Account; this should redirect you to your email provider to confirm that you want this connection to take place. Make sure to select ‘Send email on your behalf’ in the options given. When you have finalised the connection between the two services, finish this step by clicking on Create Service.</p><p>You should now see your new email service on the home page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aFpSWS6r0zaLXZUuUF7Paw.png" /></figure><p>Voila! You are now ready to work on the implementation in React.</p><h4>Implementation</h4><p>You can find some handy tips in the well-written <a href="https://www.emailjs.com/docs/">documentation</a> linked in the navbar; make sure to check it out if you are stuck or want to explore more options.</p><p>Let’s head back to our app.js and start coding!</p><p>To start with, we’ll need to import a few things, useRef from React and emailjs from the EmailJs package.</p><p>For this tutorial, we will use a basic form with four input fields that will look like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*sn7b1_T6WTko-Ta9ra3vMA.png" /></figure><p>There are a few things worth mentioning in the form above:</p><ul><li>We use the required attribute as basic validation. It means that these fields will need to be filled in before the form can be submitted. In turn, it prevents incompleted forms to be submitted by the user.</li><li>In the opening tag of the form, the onSubmit attribute would trigger the sendEmail function. You can also notice the ref attribute; we’ll touch on that shortly.</li><li>You will need to remember the value you set for each name attribute in your input fields.</li><li>The form needs to be nested inside of the div.</li></ul><p>Now that you have finished the form, we can look at the sendEmail function.</p><p>Our function is as follow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*kvdG03psJDUXlzIBG0LHhw.png" /></figure><p>We can breakdown this function to understand it better:</p><ol><li>We first pass the event (the form being submitted) e as a parameter.</li><li>e.preventDefault() would prevent the page from being reloaded upon submission.</li><li>emailjs.sendForm() takes four parameters, a service ID (what we created earlier), a template ID (we will create it in our next step), form.current (the content of the form) and a user ID (your EmailJs ID). You can find extra info <a href="https://www.emailjs.com/docs/rest-api/send-form/">here</a>.</li><li>Since emailjs.sendForm() is asynchronous we need to follow it with .then.</li><li>In the .then we either log the result if successful or the error if unsuccessful.</li></ol><p>Just above our function, let’s add the following line of code to finish our component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*--2bUMz_7tkRG5ushgWrQw.png" /></figure><p>If you are unfamiliar with what useRef is have a look at it <a href="https://reactjs.org/docs/hooks-reference.html#useref">here</a>.</p><p>In a nutshell:</p><blockquote>useRef returns a mutable ref object whose .current property is initialized to the passed argument (initialValue). The returned object will persist for the full lifetime of the component.</blockquote><p>This should be what you end up with:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*rchw2EqCp6kf2245fD0ThA.png" /></figure><h4>Email templates</h4><p>We will now create two email templates; the first one will be for the email you receive for the user, the second will be to confirm to your user that their email was sent to you.</p><p>Head back to EmailJS’ website, select the ‘ Email Templates ‘ tab on the left-hand side, then click on create &#39; Create New Template &#39;, you should now see this page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jg_JMkq5GP-ZLiHbzodKmQ.png" /></figure><p>Notice these curly brackets? They are what we’ll use as our dynamic parameters. To reflect what we send to EmailJs, we need to update the values of these parameters with the ones we set in our form (the name attributes I ask you to remember). We now have the updated templates:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u3hNXtmZrSXmbStU1BSBfg.png" /></figure><p>From here, you can move on to the next tab &#39; Auto-Reply &#39; and set it the way you like; this is a basic example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8y-F7k-s-br0gk_zqZWDfQ.png" /></figure><p>You will need to tick the box mentioning Auto-Reply if you want a reply sent to your user.</p><h4>.Env file</h4><p>The last thing we need to do for our React app to send email is set the variable in the emailjs.sendEmail() function.</p><p>For security reasons, it’s best to store them in a .env file. In your root directory, create a file and name it .env.</p><p>Once created you will need to find the following:</p><ul><li>Your user ID</li><li>Your Template ID</li><li>Your Service ID</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8TvqAoD2RDZ3s099Y41L3A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OdX_5W-PqwWXyy3ebsF6Jg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wz1btZska03c10fXXUMmhw.png" /></figure><p>In the .env file type the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*zWyxKOY1DHLY6_ydGz3Hzw.png" /></figure><p>We now need to update our function with our variables:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*u3nyISgggsQWrG_4bjxoSQ.png" /></figure><p>I have also added e.target.reset() to clear the form when it is sent.</p><p>Note that our React app might not work at this stage because we are using variables from the .env file. For our app to work we would need to re-run the command npm start or yarn start.</p><p><strong>That’s it</strong>, we can now receive emails straight from our app without creating a backend!</p><p>You can find my link below:</p><p><a href="https://github.com/gdelsaux">GitHub</a></p><p><a href="https://twitter.com/delsaux_g">Twitter</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42e669efc22a" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/set-up-emailjs-in-react-app-from-scratch-42e669efc22a">Set up EmailJs in React app from scratch.</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>