<?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 Avneesh Agarwal on Medium]]></title>
        <description><![CDATA[Stories by Avneesh Agarwal on Medium]]></description>
        <link>https://medium.com/@avneesh0612?source=rss-667e6a1a5d12------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3NCJFLX_71RexQT6_-QO4w.png</url>
            <title>Stories by Avneesh Agarwal on Medium</title>
            <link>https://medium.com/@avneesh0612?source=rss-667e6a1a5d12------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 02:37:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@avneesh0612/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[Creating an NFT minting Farcaster frame on solana]]></title>
            <link>https://medium.com/cryptostars/creating-an-nft-minting-farcaster-frame-on-solana-283ae3f5e0d3?source=rss-667e6a1a5d12------2</link>
            <guid isPermaLink="false">https://medium.com/p/283ae3f5e0d3</guid>
            <category><![CDATA[solana-blockchain]]></category>
            <category><![CDATA[nft]]></category>
            <category><![CDATA[crossmint]]></category>
            <category><![CDATA[farcaster]]></category>
            <dc:creator><![CDATA[Avneesh Agarwal]]></dc:creator>
            <pubDate>Thu, 22 Feb 2024 17:29:17 GMT</pubDate>
            <atom:updated>2024-02-22T19:18:14.332Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Creating an NFT minting Farcaster frame on solana" src="https://cdn-images-1.medium.com/max/1024/1*efNdVmHXXw5nl2XqRwaYQw.png" /></figure><h3>Introduction</h3><p>In this blog, we will create a Farcaster frame that allows users to mint NFTs on solana directly to their wallets or email after recasting and liking the cast. Try out the <a href="https://warpcast.com/avneesh/0x7dc70d75">live demo here</a>! Check out the <a href="https://twitter.com/avneesh0612/status/1760722748429472132">video demo here</a>.</p><h3>What is a Farcaster frame?</h3><p>A Frame empowers you to transform any cast into an interactive application. Seamlessly integrate features like polls, live feeds, galleries, NFT mints, etc. into Warpcast or any other Farcaster client. Frames extend the OpenGraph standard and turn static embeds into interactive experiences.</p><h3>Tools</h3><p>We’re going to use various tools to build this:</p><ul><li><a href="https://nextjs.org/">Next.js</a>: We’ll use next.js as our framework for creating the frame.</li><li><a href="https://medium.com/u/ed9c48cc1793">Crossmint</a>: To mint NFTs on solana to the user’s wallet address or email, we’ll use crossmint.</li><li><a href="https://neynar.com/">Neynar</a>: We will use neynar to check whether the user has recasted and liked the cast.</li><li><a href="https://onchainkit.xyz/">Onchainkit</a>: We will use the onchainkit to create the frame, and get the message from the frame on our server.</li></ul><h3>Setting up our NFT collection</h3><p>Head over to <a href="https://staging.crossmint.com/">Crossmint</a> (staging for devnet), then head over to the Collections tab and click on “New Collection”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QAzvZ7EOp1yE3BJZ" /></figure><p>Then, fill in the metadata for your collection, and click on Next:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2tJsFczn-r3olhmH" /></figure><p>You can either select to create a new contract or import an existing one. I don’t have a contract created so I’ll create a new one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZhBE1yYz8bnnF_yB" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AqDA2iA_MqMt8GT1" /></figure><p>Since we are going to be deploying on Solana choose Solana Devnet:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YfChuTxm20hfN2-v" /></figure><p>Here, you can enter any amount, since we won’t be doing a claim but minting the NFTs to the user’s wallet for free</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*z-M2cE4lZaliCiCm" /></figure><p>Finally, confirm the details, and click on Create Collection:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*an91WUXZs8PSEcqh" /></figure><h3>Creating the frame</h3><h3>Creating a new next.js app</h3><p>First, we need to create a new next.js app. We can do this by running the following command:</p><pre>npx create-next-app farcaster-frame</pre><p>This will create a new next.js app in the farcaster-frame directory. So, navigate to the farcaster-frame directory, and open it in your code editor.</p><p>Then, we need to install the packages we need:</p><pre>npm install @coinbase/onchainkit @bonfida/spl-name-service @neynar/nodejs-sdk @solana/web3.js # npm<br><br>yarn add @coinbase/onchainkit @bonfida/spl-name-service @neynar/nodejs-sdk @solana/web3.js # yarn</pre><h3>Creating the frame</h3><p>Firstly, let’s clean the src/app/layout.tsx file since we don&#39;t need any styling or metadata in the layout:</p><pre>export const viewport = {<br>  width: &quot;device-width&quot;,<br>  initialScale: 1.0,<br>};<br><br>export default function RootLayout({<br>  children,<br>}: {<br>  children: React.ReactNode;<br>}) {<br>  return (<br>    &lt;html lang=&quot;en&quot;&gt;<br>      &lt;body&gt;{children}&lt;/body&gt;<br>    &lt;/html&gt;<br>  );<br>}</pre><p>Then, head over to the page.tsx file and replace the content with the following:</p><pre>import { getFrameMetadata } from &quot;@coinbase/onchainkit&quot;;<br>import type { Metadata } from &quot;next&quot;;<br><br>const NEXT_PUBLIC_URL = process.env.NEXT_PUBLIC_URL;<br><br>const frameMetadata = getFrameMetadata({<br>  buttons: [<br>    {<br>      label: &quot;Mint an NFT&quot;,<br>      action: &quot;post&quot;,<br>    },<br>  ],<br>  image: {<br>    src: `${NEXT_PUBLIC_URL}/default.png`,<br>    aspectRatio: &quot;1.91:1&quot;,<br>  },<br>  input: {<br>    text: &quot;enter...&quot;,<br>  },<br>  postUrl: `${NEXT_PUBLIC_URL}/api/frame`,<br>});<br><br>export const metadata: Metadata = {<br>  title: &quot;Mint an NFT&quot;,<br>  description: &quot;Mint an NFT&quot;,<br>  openGraph: {<br>    title: &quot;Mint an NFT&quot;,<br>    description: &quot;Mint an NFT&quot;,<br>    images: [`${NEXT_PUBLIC_URL}/default.png`],<br>  },<br>  other: {<br>    ...frameMetadata,<br>  },<br>};<br><br>export default function Page() {<br>  return (<br>    &lt;&gt;<br>      &lt;h1&gt;Mint an NFT&lt;/h1&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><p>Here, we are creating the frameMetadata which contains the buttons, image, input, and postUrl. We just have a single button which creates an API request to the /api/frame endpoint. And, we take in the wallet address, domain or email as input.</p><p>Then, we export the metadata which contains the frameMetadata, and some other metadata like title, description, and openGraph.</p><p>Finally, we are returning a simple h1 tag with the text “Mint an NFT”. This will be displayed on the website, but this has nothing to do with the frame.</p><p>As you can see we are using a default.png image. This is the image which will be displayed in the frame at the beginning. You can replace this with your image. You can take a look at the image I am using <a href="https://blog.avneesh.tech/TODO">here</a>.</p><h3>Creating the API endpoint</h3><p>Now, we will create the API endpoint which will get called once the user hits the mint button. Create a new file called route.ts in the app/api/frame directory, and add the following content:</p><pre>import {<br>  FrameRequest,<br>  getFrameMessage,<br>  getFrameHtmlResponse,<br>} from &quot;@coinbase/onchainkit&quot;;<br>import { NextRequest, NextResponse } from &quot;next/server&quot;;<br>import { getDomainKeySync, NameRegistryState } from &quot;@bonfida/spl-name-service&quot;;<br>import { Connection, PublicKey } from &quot;@solana/web3.js&quot;;<br><br>export async function POST(req: NextRequest): Promise&lt;Response&gt; {<br>  let input: string | undefined = &quot;&quot;;<br>  let recipientAddress = &quot;&quot;;<br>  const NEXT_PUBLIC_URL = process.env.NEXT_PUBLIC_URL;<br>  let isEmail = false;<br>  const body: FrameRequest = await req.json();<br><br>  try {<br>    const { message } = await getFrameMessage(body, {<br>      neynarApiKey: &quot;NEYNAR_ONCHAIN_KIT&quot;,<br>    });<br><br>    if (message?.input) {<br>      input = message.input;<br>    }<br><br>    if (!input) {<br>      return new NextResponse(<br>        getFrameHtmlResponse({<br>          image: {<br>            src: `${NEXT_PUBLIC_URL}/error2.png`,<br>          },<br>          ogTitle: &quot;Error&quot;,<br>        })<br>      );<br>    }<br><br>    if (input.slice(-4) === &quot;.sol&quot;) {<br>      const { pubkey } = getDomainKeySync(input);<br>      const connection = new Connection(&quot;https://api.mainnet-beta.solana.com&quot;);<br>      const { registry } = await NameRegistryState.retrieve(connection, pubkey);<br><br>      const pubKey = new PublicKey(registry.owner);<br>      recipientAddress = pubKey.toBase58();<br>    } else if (input.includes(&quot;@&quot;)) {<br>      isEmail = true;<br>      recipientAddress = `email:${input}:solana`;<br>    } else {<br>      recipientAddress = `solana:${input}`;<br>    }<br><br>    return new NextResponse(<br>      getFrameHtmlResponse({<br>        image: {<br>          src: `${NEXT_PUBLIC_URL}/success.png`,<br>        },<br>      })<br>    );<br>  } catch (error) {<br>    return new NextResponse(<br>      getFrameHtmlResponse({<br>        image: {<br>          src: `${NEXT_PUBLIC_URL}/error.png`,<br>        },<br>        ogTitle: &quot;Error&quot;,<br>      })<br>    );<br>  }<br>}<br><br>export const dynamic = &quot;force-dynamic&quot;;</pre><p>A lot is going on here, so let’s break it down:</p><ul><li>We are getting the frame message from the request body using the onchainkit and then getting the input from the message.</li><li>If there’s no input, we return an error image. I have created a simple error image which you can use, or you can create your own or even use an image generator to create specific errors but for now, I will use the images that I have created.</li><li>Then, we determine whether the input is a domain, email, or wallet address. If it’s a domain, we get the wallet address from the domain using Bonfida. If it’s an email, we set the recipient address to email:${input}:solana. So, the user can view it in his Crossmint wallet. If it&#39;s a wallet address, we set the recipient address to solana:${input}.</li></ul><p>Now, let’s mint the NFT to the user’s wallet using crossmint. To do that add the following:</p><pre>const env = process.env.CROSSMINT_ENV || &quot;staging&quot;;<br>const crossmintURL = `https://${env}.crossmint.com/api/2022-06-09/collections/ENTER_YOUR_COLLECTION_ID/nfts`;<br>const crossmintOptions = {<br>  method: &quot;POST&quot;,<br>  headers: {<br>    accept: &quot;application/json&quot;,<br>    &quot;content-type&quot;: &quot;application/json&quot;,<br>    &quot;x-api-key&quot;: process.env.CROSSMINT_API_KEY!,<br>  },<br>  body: JSON.stringify({<br>    recipient: recipientAddress,<br>    metadata: {<br>      name: &quot;Cool NFT 😎&quot;,<br>      image: `${NEXT_PUBLIC_URL}/nft.png`,<br>      description: &quot;This is my cool NFT&quot;,<br>    },<br>  }),<br>};</pre><p>Replace ENTER_YOUR_COLLECTION_ID with your collection ID. You can get your collection ID from the collections tab in Crossmint. Also, replace the metadata and nft.png with the image you want to use for the NFT. I have added the image to the public directory in the next.js app.</p><p>We are using the CROSSMINT_API_KEY env variable here, I&#39;ll go over where to get it in the getting to production section.</p><p>Then, replace return new NextResponse with the following:</p><pre>return new NextResponse(<br>  getFrameHtmlResponse({<br>    image: {<br>      src: `${NEXT_PUBLIC_URL}/success.png`,<br>    },<br>    buttons: [<br>      isEmail<br>        ? {<br>            label: &quot;View your NFT on crossmint&quot;,<br>            action: &quot;link&quot;,<br>            target: `https://${env}.crossmint.com/user/collection`,<br>          }<br>        : {<br>            label: &quot;Your NFT will arrive soon&quot;,<br>          },<br>    ],<br>  })<br>);</pre><p>Once the API call is successful, the user will see a success image, and a button to view the NFT on Crossmint. If the recipient address is an email, the user will see a button to view the NFT on Crossmint. If the recipient address is a wallet address, the user will see a message that the NFT will arrive soon.</p><h3>Checking whether the user has recasted and liked the cast</h3><p>This is an optional step but if we want to get some more engagement on the cast, we can make it compulsory for the users to recast and like the cast before they can mint the NFT. To do that, we can use neynar. Add the following to the route.ts file:</p><pre>if (process.env.WARPCAST_HASH &amp;&amp; process.env.NEYNAR_API_KEY) {<br>  const neynarURL = `https://api.neynar.com/v2/farcaster/cast?identifier=${process.env.WARPCAST_HASH}&amp;type=hash`;<br><br>  const neynarResponse = await fetch(neynarURL, {<br>    headers: {<br>      api_key: process.env.NEYNAR_API_KEY,<br>      &quot;content-type&quot;: &quot;application/json&quot;,<br>    },<br>    method: &quot;GET&quot;,<br>  });<br><br>  const data = await neynarResponse.json();<br><br>  const reactions = await data.cast.reactions;<br><br>  const hasRecasted = reactions.recasts.some(<br>    (recast: { fid: Number }) =&gt; recast.fid === message?.interactor.fid<br>  );<br>  const hasLiked = reactions.likes.some(<br>    (likes: { fid: Number }) =&gt; likes.fid === message?.interactor.fid<br>  );<br><br>  if (!hasRecasted || !hasLiked) {<br>    return new NextResponse(<br>      getFrameHtmlResponse({<br>        image: {<br>          src: `${NEXT_PUBLIC_URL}/error1.png`,<br>        },<br>        postUrl: `${NEXT_PUBLIC_URL}/api/frame`,<br>        buttons: [<br>          {<br>            label: &quot;Try again&quot;,<br>            action: &quot;post&quot;,<br>          },<br>        ],<br>      })<br>    );<br>  }<br>}</pre><p>Here, we are making a call to Neynar’s api and getting the cast. We are then checking whether the array of recasts and likes contains the user’s fid. If it doesn’t, we return an error image and a button to try again.</p><p>The final route.ts file should look something like this:</p><pre>import {<br>  FrameRequest,<br>  getFrameMessage,<br>  getFrameHtmlResponse,<br>} from &quot;@coinbase/onchainkit&quot;;<br>import { NextRequest, NextResponse } from &quot;next/server&quot;;<br>import { getDomainKeySync, NameRegistryState } from &quot;@bonfida/spl-name-service&quot;;<br>import { Connection, PublicKey } from &quot;@solana/web3.js&quot;;<br><br>export async function POST(req: NextRequest): Promise&lt;Response&gt; {<br>  let input: string | undefined = &quot;&quot;;<br>  let recipientAddress = &quot;&quot;;<br>  const NEXT_PUBLIC_URL = process.env.NEXT_PUBLIC_URL;<br>  let isEmail = false;<br>  const body: FrameRequest = await req.json();<br><br>  try {<br>    const { message } = await getFrameMessage(body, {<br>      neynarApiKey: &quot;NEYNAR_ONCHAIN_KIT&quot;,<br>    });<br><br>    if (message?.input) {<br>      input = message.input;<br>    }<br><br>    if (!input) {<br>      return new NextResponse(<br>        getFrameHtmlResponse({<br>          image: {<br>            src: `${NEXT_PUBLIC_URL}/error2.png`,<br>          },<br>          ogTitle: &quot;Error&quot;,<br>        })<br>      );<br>    }<br><br>    if (process.env.WARPCAST_HASH &amp;&amp; process.env.NEYNAR_API_KEY) {<br>      const neynarURL = `https://api.neynar.com/v2/farcaster/cast?identifier=${process.env.WARPCAST_HASH}&amp;type=hash`;<br><br>      const neynarResponse = await fetch(neynarURL, {<br>        headers: {<br>          api_key: process.env.NEYNAR_API_KEY,<br>          &quot;content-type&quot;: &quot;application/json&quot;,<br>        },<br>        method: &quot;GET&quot;,<br>      });<br><br>      const data = await neynarResponse.json();<br><br>      const reactions = await data.cast.reactions;<br><br>      const hasRecasted = reactions.recasts.some(<br>        (recast: { fid: Number }) =&gt; recast.fid === message?.interactor.fid<br>      );<br>      const hasLiked = reactions.likes.some(<br>        (likes: { fid: Number }) =&gt; likes.fid === message?.interactor.fid<br>      );<br><br>      if (!hasRecasted || !hasLiked) {<br>        return new NextResponse(<br>          getFrameHtmlResponse({<br>            image: {<br>              src: `${NEXT_PUBLIC_URL}/error1.png`,<br>            },<br>            postUrl: `${NEXT_PUBLIC_URL}/api/frame`,<br>            buttons: [<br>              {<br>                label: &quot;Try again&quot;,<br>                action: &quot;post&quot;,<br>              },<br>            ],<br>          })<br>        );<br>      }<br>    }<br><br>    if (input.slice(-4) === &quot;.sol&quot;) {<br>      const { pubkey } = getDomainKeySync(input);<br>      const connection = new Connection(&quot;https://api.mainnet-beta.solana.com&quot;);<br>      const { registry } = await NameRegistryState.retrieve(connection, pubkey);<br><br>      const pubKey = new PublicKey(registry.owner);<br>      recipientAddress = pubKey.toBase58();<br>    } else if (input.includes(&quot;@&quot;)) {<br>      isEmail = true;<br>      recipientAddress = `email:${input}:solana`;<br>    } else {<br>      recipientAddress = `solana:${input}`;<br>    }<br><br>    const crossmintURL = `https://${env}.crossmint.com/api/2022-06-09/collections/56d9e10d-3caf-46a8-80a3-a507d034e51f/nfts`;<br>    const crossmintOptions = {<br>      method: &quot;POST&quot;,<br>      headers: {<br>        accept: &quot;application/json&quot;,<br>        &quot;content-type&quot;: &quot;application/json&quot;,<br>        &quot;x-api-key&quot;: process.env.CROSSMINT_API_KEY!,<br>      },<br>      body: JSON.stringify({<br>        recipient: recipientAddress,<br>        metadata: {<br>          name: &quot;Cool NFT 😎&quot;,<br>          image: `${NEXT_PUBLIC_URL}/nft.png`,<br>          description: &quot;This is my cool NFT&quot;,<br>        },<br>      }),<br>    };<br><br>    const response = await fetch(crossmintURL, crossmintOptions);<br>    await response.json();<br><br>    return new NextResponse(<br>      getFrameHtmlResponse({<br>        image: {<br>          src: `${NEXT_PUBLIC_URL}/success.png`,<br>        },<br>        buttons: [<br>          isEmail<br>            ? {<br>                label: &quot;View your NFT on crossmint&quot;,<br>                action: &quot;link&quot;,<br>                target: `https://${env}.crossmint.com/user/collection`,<br>              }<br>            : {<br>                label: &quot;Your NFT will arrive soon&quot;,<br>              },<br>        ],<br>      })<br>    );<br>  } catch (error) {<br>    return new NextResponse(<br>      getFrameHtmlResponse({<br>        image: {<br>          src: `${NEXT_PUBLIC_URL}/error.png`,<br>        },<br>        ogTitle: &quot;Error&quot;,<br>      })<br>    );<br>  }<br>}<br><br>export const dynamic = &quot;force-dynamic&quot;;</pre><p>That’s it! We have created the frame. Now, let’s get to production.</p><h3>Getting to production</h3><p>Create a new <a href="https://github.com/new">GitHub repository</a> and push the code to the repository.</p><pre>git add .<br>git commit -m &quot;Initial commit&quot;<br>git remote add origin https://github.com/&lt;username&gt;/&lt;repo_name&gt;.git<br>git branch -M main<br>git push -u origin main</pre><p>Then, head over to <a href="https://vercel.com/">Vercel</a> and import the repository. Once you have imported the repository, head over to the environment variables and add the following environment variables:</p><ul><li>NEXT_PUBLIC_URL: The URL of your next.js app.</li><li>CROSSMINT_API_KEY: The API key for crossmint. Head over to the <a href="https://staging.crossmint.com/console/projects/apiKeys">API keys section</a> in the Crossmint dashboard and create a new server key with permission to mint NFTs. Then, add the key as an environment variable.</li><li>CROSSMINT_ENV: If you switch over your app from testnet to mainnet, you can add the environment variable CROSSMINT_ENV and set it to www.</li></ul><p>If you want to check whether the user has recasted and liked the cast, you can add the following environment variables:</p><ul><li>WARPCAST_HASH: The hash of the cast which you want to check has been recasted and liked.</li><li>NEYNAR_API_KEY The API key for neynar. You can get it from the <a href="https://dev.neynar.com/">neynar dashboard</a>.</li></ul><p>Then, head over to the domains tab and add your domain.</p><p>That’s it! You have created a frame that allows users to mint NFTs on solana directly to their wallets or email after recasting and liking the cast.</p><h3>Test the frame</h3><p>You can go to the <a href="https://warpcast.com/~/developers/frames">Frames validator</a> on Warpcast and test your frame. If everything looks good, make a cast with the URL of your frame and share it with your friends to test it out!</p><h3>Conclusion</h3><p>This guide taught us how to create a Farcaster frame that allows users to mint NFTs on solana directly to their wallets or email after recasting and liking the cast. You learned a lot, now pat yourself on the back and share your amazing frames with me!</p><p><a href="https://github.com/avneesh0612/farcaster-frame-solana">GitHub Repo</a></p><p><a href="https://farcaster.com/">Farcaster</a></p><p><a href="https://crossmint.com/">Crossmint</a></p><p><a href="https://neynar.com/">Neynar</a></p><p><a href="https://links.avneesh.tech/">Connect with me</a></p><p><em>Originally published at </em><a href="https://blog.avneesh.tech/farcaster-frames-solana"><em>https://blog.avneesh.tech</em></a><em> on February 22, 2024.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=283ae3f5e0d3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cryptostars/creating-an-nft-minting-farcaster-frame-on-solana-283ae3f5e0d3">Creating an NFT minting Farcaster frame on solana</a> was originally published in <a href="https://medium.com/cryptostars">CryptoStars</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Start a Headless E2E eCommerce Store in No Time with Medusa ️]]></title>
            <link>https://avneesh0612.medium.com/how-to-start-a-headless-e2e-ecommerce-store-in-no-time-with-medusa-%EF%B8%8F-6dc282096e7?source=rss-667e6a1a5d12------2</link>
            <guid isPermaLink="false">https://medium.com/p/6dc282096e7</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[medusa]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Avneesh Agarwal]]></dc:creator>
            <pubDate>Fri, 07 Jan 2022 14:07:22 GMT</pubDate>
            <atom:updated>2022-01-07T14:07:22.342Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vPwSoffaQwbmlklOEdqdcg.png" /></figure><p>What’s up, everyone? In this article, we are going to create a headless e-commerce application using an open-source alternative to Shopify: <a href="https://www.medusajs.com/"><strong>Medusa</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*6EIKtUwEeMw-5B8P" /></figure><h3>What are we building?</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.loom.com%2Fembed%2F0b3dd851cb2d449f8c452369aa514017&amp;display_name=Loom&amp;url=https%3A%2F%2Fwww.loom.com%2Fshare%2F0b3dd851cb2d449f8c452369aa514017&amp;image=https%3A%2F%2Fcdn.loom.com%2Fsessions%2Fthumbnails%2F0b3dd851cb2d449f8c452369aa514017-00001.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=loom" width="1280" height="960" frameborder="0" scrolling="no"><a href="https://medium.com/media/a82b077751f8953eb997c848336dd8e5/href">https://medium.com/media/a82b077751f8953eb997c848336dd8e5/href</a></iframe><h3>What is Medusa?</h3><p>Medusa is an open-source headless commerce platform which makes it super easy to build an e-commerce site quickly! It is an amazing tool so let’s see why to choose Medusa:</p><ul><li>Easy to use</li><li>Scalable</li><li>Open-source</li><li>Easily customizable</li><li>Free to get started with!</li><li>Large supporting community to help</li><li>Many, easy to use integrations</li></ul><h3>Prerequisites</h3><p>We are going to need some stuff installed on our machine so let’s see what those are.</p><h4>Node.js</h4><p>Our backend server is built with Node.js so we are gonna need it to run the server. Our frontend is also gonna be built with Next.js which requires npm so we are gonna need it for that too! So, go to <a href="https://nodejs.org/en/">the Node.js website</a> and install recommended version.</p><h4>PostgreSQL</h4><p>For storing data of your e-commerce website Medusa uses Postgres. You can go to the <a href="https://www.postgresql.org/download/">site</a> to install Postgres for your system!</p><h4>Redis</h4><p>Redis is another database commonly used for caching. You can download it from <a href="https://redis.io/">here</a>.</p><h4>Medusa CLI</h4><p>Finally, we are going to need the Medusa CLI. Since we already have Node.js installed on our machine, we can easily install it from npm using this command:</p><pre>npm i -g @medusajs/medusa-cli</pre><h3>Quickstep to step guide for beginners</h3><h4>Creating our backend server</h4><p>We are going to need a backend for your e-commerce store so in this part let’s see how to build it!</p><p><strong>Create a starter server using Medusa</strong></p><p>The Medusa CLI makes it super easy to create a new server. So, run this command:</p><pre>medusa new my-medusa-server --seed</pre><p>This is going to create a basic server for us to start with, a Postgres database, and the — seed flag is also going to add some test data to the database.</p><p><strong>Starting the server</strong></p><p>Navigate into the app:</p><pre>cd my-medusa-server</pre><p>Start the server, using Medusa:</p><pre>medusa develop</pre><p>This will start a server on <a href="http://localhost:9000/">http://localhost:9000</a></p><p>I am going to use Next.js for the front end of our store, Medusa also supports Gatsby and Create React app. I am going to use a starter template. So run this command:</p><pre>npx create-next-app -e https://github.com/medusajs/nextjs-starter-medusa my-medusa-storefront</pre><p>This will create a new next js project for us. If you want to use TailwindCSS, you can try out this <a href="https://github.com/avneesh0612/next-medusa-tailwind-template">template </a>that I created.</p><p>Rename .env.template to .env.local. You can also do it with one command:</p><pre>mv .env.template .env.local</pre><p>Run the app.</p><p>If you now go to <a href="http://localhost:8000/">localhost:8000</a>, you will be able to see a simple frontend for our store.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*c-Q7WxPRwr_xZ1ho" /></figure><p>This can be customized too! So, open it in your favorite code editor I am going to use VS Code.</p><p>If you have worked with next.js before it is going to look like a normal Next.js app to you! Let’s start by changing the logo of the app. Go to components/layout/nav-bar.jsx and change the src of the Image to your logo. For now, I am going to use a simple house image from icons8. You might need to change the width and height based on the dimensions of your image:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd9105274b15a71bcf472166362ad713/href">https://medium.com/media/fd9105274b15a71bcf472166362ad713/href</a></iframe><p>Now, the logo has been changed!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*onBd34WuhGhrhtuP" /></figure><p><strong>Customizing the colors</strong></p><p>Go to globals.css and inside :root you will see a bunch of colors, replace those with your brand colors. This will change the overall theme of the site, if you want to change more CSS then you can just go to that component and customize it 😉. After some tweaks and changes, you will have a completely custom functional store!</p><p>By doing only this much, our app is up and running!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.loom.com%2Fembed%2F0b3dd851cb2d449f8c452369aa514017&amp;display_name=Loom&amp;url=https%3A%2F%2Fwww.loom.com%2Fshare%2F0b3dd851cb2d449f8c452369aa514017&amp;image=https%3A%2F%2Fcdn.loom.com%2Fsessions%2Fthumbnails%2F0b3dd851cb2d449f8c452369aa514017-00001.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=loom" width="1280" height="960" frameborder="0" scrolling="no"><a href="https://medium.com/media/a82b077751f8953eb997c848336dd8e5/href">https://medium.com/media/a82b077751f8953eb997c848336dd8e5/href</a></iframe><h3>Contributing to Medusa as a beginner</h3><p>If you are fascinated by open-source projects and contributing to amazing projects then you should try to contribute to Medusa. The first question would be <strong>how</strong>? If you find an issue in a package, or the site then creates a <em>Pull Request</em> fixing it. If you don’t know how to create a pull request check out this <a href="https://blog.avneesh.tech/how-to-contribute-to-an-open-source-project">article </a>and it is super easy! Medusa has many repositories under its <a href="https://github.com/medusajs/">organization</a>. The most popular one is the <a href="https://github.com/medusajs/medusa">main repository</a>. You can contribute to it through documentation, issues, and many more!</p><h3>Conclusion</h3><p>I hope you could set up your e-commerce site using medusa easily. If you have any questions let me know in the comments. 👇😉</p><h4>Useful links</h4><p><a href="https://github.com/avneesh0612/medusa-store">GitHub Repo</a></p><p><a href="https://www.medusajs.com/">Medusa</a></p><p><a href="https://discord.gg/NZZ4ymyESg">Join the Medusa discord server</a></p><p><a href="https://links.avneesh.tech/">Connect with me</a></p><p><em>More content at </em><a href="http://plainenglish.io/"><em>plainenglish.io</em></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><em>free weekly newsletter</em></a><em>. Get exclusive access to writing opportunities and advice in our </em><a href="https://discord.gg/GtDtUAvyhW"><em>community Discord</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6dc282096e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Metamask authentication with Moralis in Next.js]]></title>
            <link>https://medium.com/geekculture/metamask-authentication-with-moralis-in-next-js-33972b242b05?source=rss-667e6a1a5d12------2</link>
            <guid isPermaLink="false">https://medium.com/p/33972b242b05</guid>
            <category><![CDATA[metamask]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[nextjs]]></category>
            <dc:creator><![CDATA[Avneesh Agarwal]]></dc:creator>
            <pubDate>Fri, 03 Dec 2021 15:57:23 GMT</pubDate>
            <atom:updated>2021-12-04T10:30:04.714Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ctu1aEMQF3yO6kgRyazDYg.png" /></figure><p>If you haven’t been living under a rock you have probably heard of Web 3.0!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*koW9nOO82-J1bq4Q.gif" /></figure><p>One of the most important parts of a full-stack is authentication. So let’s see how to authorize users with their Metamask wallet in a Next.js app.</p><p>If you don’t know what is metamask then check out their <a href="https://metamask.io/">website</a></p><h3>Setting up the app</h3><p><strong>Create a new next app</strong></p><pre>npx create-next-app next-metamask</pre><p><strong>Navigate into the app</strong></p><pre>cd next-metamask</pre><p><strong>Installing the required dependencies</strong></p><pre>npm i <a href="http://twitter.com/walletconnect/web3-provider">@walletconnect/web3-provider</a> moralis react-moralis # npm</pre><pre>yarn add <a href="http://twitter.com/walletconnect/web3-provider">@walletconnect/web3-provider</a> moralis react-moralis # yarn</pre><p><strong>Start the server</strong></p><pre>npm run dev # npm</pre><pre>yarn dev # yarn</pre><h3>Get Moralis Credentials</h3><p>Go to <a href="https://moralis.io/">moralis</a> and signup/login. After that click on Create new Server and select TestNet Server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZMd7Qm879qVCC8vV" /></figure><p>By selecting it you will see a popup. Fill in the details, and click the Add Instance button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/0*CN57cg4pxcFieiuV" /></figure><p>After the server is created click on view details</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AMEAKy93UPRZjS03" /></figure><p>We are going to need the server URL and Application ID</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/0*4OA4PUtVahK4jrWA" /></figure><h3>Building out the authentication system</h3><p><strong>Adding the environment variables</strong></p><p>Create a .env.local file in the root of your folder and add the env variables like this-</p><pre>NEXT_PUBLIC_MORALIS_APP_ID=&lt;app_id&gt;<br>NEXT_PUBLIC_MORALIS_SERVER_ID=&lt;server_id&gt;</pre><p>You need to replace the values of the variables with the credentials you got from Moralis.</p><p><strong>Wrap the app in a MoralisProvider</strong></p><p>Go to _app.js and wrap the &lt;Component {...pageProps} /&gt; with the Moralis Provider with the env variables like this-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84dc160231549ab97b44a77d8e1dabaf/href">https://medium.com/media/84dc160231549ab97b44a77d8e1dabaf/href</a></iframe><p>Now import MoralisProvider from react-moralis</p><pre>import { MoralisProvider } from &quot;react-moralis&quot;;</pre><p><strong>Creating the sign-in button</strong></p><p>I am going to do create the login button on the home page, feel free to create it on any page you need.</p><p>Get the authenticate function from the useMoralis hook-</p><pre>const { authenticate } = useMoralis();</pre><p>You also need to import the hook from react-moralis</p><pre>import { useMoralis } from &quot;react-moralis&quot;;</pre><p>Create a button like this-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b97bd70ac7e35209800ea5b8cabbac27/href">https://medium.com/media/b97bd70ac7e35209800ea5b8cabbac27/href</a></iframe><p>Now if we click on sign in, it will open the metamask extension for sign in.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.loom.com%2Fembed%2Fc2b1c9936ad44185810d9978ea5c2193&amp;display_name=Loom&amp;url=https%3A%2F%2Fwww.loom.com%2Fshare%2Fc2b1c9936ad44185810d9978ea5c2193%3Ft%3D0&amp;image=https%3A%2F%2Fcdn.loom.com%2Fsessions%2Fthumbnails%2Fc2b1c9936ad44185810d9978ea5c2193-1638536705405.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=loom" width="1280" height="960" frameborder="0" scrolling="no"><a href="https://medium.com/media/f413a3c3edf3071fb91c1d83375212b8/href">https://medium.com/media/f413a3c3edf3071fb91c1d83375212b8/href</a></iframe><p><strong>Show signout button if the user is signed out</strong></p><p>We need to get a few more things from the useMoralis hook like this-</p><pre>const { authenticate, isAuthenticated, logout } = useMoralis();</pre><p>Create a ternary operator to show the logout button, if the user is signed in otherwise show the sign-in button-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc3b76c74e7ada91f1ac72e329dfd8a8/href">https://medium.com/media/fc3b76c74e7ada91f1ac72e329dfd8a8/href</a></iframe><p>Now our sign in and sign out is working 🥳🥳</p><p><strong>Getting the user data</strong></p><p>Let’s see how to get some basic data like their eth address and username.</p><p>When the user is authenticated, you can add this fragment to show the userName and their address wallet-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f4033d0407e0d8e0d1b91ea437572be/href">https://medium.com/media/1f4033d0407e0d8e0d1b91ea437572be/href</a></iframe><p>You need to get the user from the useMoralis hook as well-</p><pre>const { authenticate, isAuthenticated, logout, user } = useMoralis();</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gq1w27e6y98wb1K_" /></figure><p>The userName is very random 😂but it can help in some cases and the eth address can be used for transactions.</p><h3>Signing off</h3><p>It was this easy to implement authentication of metamask with moralis 🤯</p><p>Hope you found this tutorial useful and stay tuned for more of these web 3.0 tutorials ✌️</p><p><a href="https://github.com/avneesh0612/metamask-next">GitHub repo</a></p><p><a href="https://moralis.io/">Moralis</a></p><p><a href="https://metamask.io/">Metamask</a></p><p><a href="https://links.avneesh.tech/">Connect with me</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33972b242b05" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/metamask-authentication-with-moralis-in-next-js-33972b242b05">Metamask authentication with Moralis in Next.js</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[Build a Quiz App with Next.js and Tailwind CSS]]></title>
            <link>https://javascript.plainenglish.io/build-a-quiz-app-with-next-js-and-tailwindcss-f61b14148661?source=rss-667e6a1a5d12------2</link>
            <guid isPermaLink="false">https://medium.com/p/f61b14148661</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[tailwind-css]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Avneesh Agarwal]]></dc:creator>
            <pubDate>Mon, 08 Nov 2021 04:20:57 GMT</pubDate>
            <atom:updated>2021-11-09T05:53:17.610Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Q1RtqjBgOnf_U8tagTZYg.png" /></figure><p>Hey, everyone! This is going to be a tutorial plus a challenge. I also have a giveaway at the end so stay tuned ;)</p><h3>Demo</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.loom.com%2Fembed%2F057cf700f0a24f22ba1f3528f8f9e585&amp;display_name=Loom&amp;url=https%3A%2F%2Fwww.loom.com%2Fshare%2F057cf700f0a24f22ba1f3528f8f9e585%3Ft%3D0&amp;image=https%3A%2F%2Fcdn.loom.com%2Fsessions%2Fthumbnails%2F057cf700f0a24f22ba1f3528f8f9e585-00001.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=loom" width="1280" height="960" frameborder="0" scrolling="no"><a href="https://medium.com/media/7cf208bd359146dc84bed74c7583a469/href">https://medium.com/media/7cf208bd359146dc84bed74c7583a469/href</a></iframe><p>You can try it out yourself here- <a href="https://quiz-challenge.vercel.app/">quiz-challenge.vercel.app</a></p><h3>Setting up</h3><h4>Creating a Next.js app with Tailwind CSS</h4><p>I am going to use Tailwind for the basic stylings needed in the app</p><pre>npx create-next-app next-stripe-demo -e with-tailwindcss</pre><h4>Cleanup</h4><p>Delete everything in <strong><em>pages/index.js</em></strong> after the Head</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c14b92c032ecf93eb901cdab5d5e623/href">https://medium.com/media/0c14b92c032ecf93eb901cdab5d5e623/href</a></iframe><h4>Starting the app</h4><pre>npm run dev # npm<br>yarn dev # yarn</pre><h3>Create a few questions</h3><p>We are going to use the questions from a JSON array, so create a questions.json file in the root of the directory. The questions array should look like this-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6f0a32a71af5d3d82c3082f1e5536f9/href">https://medium.com/media/c6f0a32a71af5d3d82c3082f1e5536f9/href</a></iframe><h3>Creating the UI for the Quiz</h3><p>Our quiz will look like this-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xxOttkixebNPFpNK" /></figure><p><strong>Styling the container of our app.</strong></p><p>I will add the following styles to the div containing the app-</p><pre>&lt;div className=&quot;flex flex-col w-screen px-5 h-screen bg-[#1A1A1A] justify-center items-center&quot;&gt;</pre><p>This will give us a blank screen with the background color- #1A1A1A.</p><p><strong>Question section</strong></p><p>We are going to hard code the values for now.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a29d807f956790bc097cb036e2a2dd3/href">https://medium.com/media/6a29d807f956790bc097cb036e2a2dd3/href</a></iframe><p>Now our app is looking like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vlWn63dDpwY3dAxo" /></figure><p><strong>Creating the answers</strong></p><p>We are going to map through the answers to the first question, to show the options.</p><p>we also need to import questions from the questions.json file, so add this import line-</p><p>It will now give us all the options with a radio button-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dc0KE_nAYVAHR91b" /></figure><p>The radio button doesn’t go well with our theme, so I am going to add some custom styles for it in globals.css, so follow the instructions-</p><ul><li>Create a styles folder and globals.css file inside it</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/394/0*m287cvoxpHNSR6ju" /></figure><ul><li>Inside globals.css add the following-</li></ul><pre>@tailwind base;<br>@tailwind components;<br>@tailwind utilities;</pre><ul><li>Import globals.css instead of tailwindcss/tailwind.css in _app.js</li></ul><pre>import &quot;../styles/globals.css&quot;;</pre><ul><li>Add the styles for the custom radio button</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/615addf14bbca8f08a48f0f603950c00/href">https://medium.com/media/615addf14bbca8f08a48f0f603950c00/href</a></iframe><p>Now it gives us a better radio button that matches the theme like this-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QPnDCwXqx2l0TbXA" /></figure><p><strong>Adding the buttons to navigate through the questions</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b116a139b928dbf2be9b6679682363f0/href">https://medium.com/media/b116a139b928dbf2be9b6679682363f0/href</a></iframe><p>This gives us the buttons for navigating as follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OtARn3D47RHuNCXj.png" /></figure><p>With this, we are done setting up the UI.</p><h3>Adding the logic for our quiz</h3><p><strong>Navigation</strong></p><p>We are first going to build the navigation functionality</p><p>Create a state for the current question-</p><pre>const [currentQuestion, setCurrentQuestion] = useState(0);</pre><p>Create 2 functions to handle Next and Previous-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79e7c4eb8ae9be12fc1fff1ee00a7699/href">https://medium.com/media/79e7c4eb8ae9be12fc1fff1ee00a7699/href</a></iframe><p>Assigning the functions to the respective buttons</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/701d28ce9f1ff7431a0cc8e0464b4845/href">https://medium.com/media/701d28ce9f1ff7431a0cc8e0464b4845/href</a></iframe><p>Remove the hardcoded values for the question-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5a3e0e1986fa4f6f49762d6b6ef5875/href">https://medium.com/media/d5a3e0e1986fa4f6f49762d6b6ef5875/href</a></iframe><p>Map the answers for the current question instead of the first question-</p><pre>questions[currentQuestion].answerOptions.map</pre><p>Now we can easily move through the questions 🎉</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.loom.com%2Fembed%2Ff058f666aacd457ba4c00a432b040e89&amp;display_name=Loom&amp;url=https%3A%2F%2Fwww.loom.com%2Fshare%2Ff058f666aacd457ba4c00a432b040e89&amp;image=https%3A%2F%2Fcdn.loom.com%2Fsessions%2Fthumbnails%2Ff058f666aacd457ba4c00a432b040e89-00001.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=loom" width="1280" height="960" frameborder="0" scrolling="no"><a href="https://medium.com/media/e99e164610a9eec6215d3e0087990c1e/href">https://medium.com/media/e99e164610a9eec6215d3e0087990c1e/href</a></iframe><p><strong>Ability to select options</strong></p><p>Create a state to hold all the selected answers-</p><pre>const [selectedOptions, setSelectedOptions] = useState([]);</pre><p>We will now make a function to set the selected option-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b57a42ba8c769e49fef5a678d65b2b84/href">https://medium.com/media/b57a42ba8c769e49fef5a678d65b2b84/href</a></iframe><p>Now, we need to trigger in onClick of the option and check the radio button-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/291137697db79794f2f28f1a324bee9e/href">https://medium.com/media/291137697db79794f2f28f1a324bee9e/href</a></iframe><p>Now if you select an option then it will be stored as an object in the selectedOptions state. To check this let&#39;s console.log selectedOptions in handleAnswerOption-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b77dc3da4eb33d0a4b135b180daa3ecc/href">https://medium.com/media/b77dc3da4eb33d0a4b135b180daa3ecc/href</a></iframe><p>After clicking the options, it will show an array of options selected like this-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/0*wpQLMMfwe7-9cL5v" /></figure><p><strong>Calculating and showing the score</strong></p><p>Make 2 states, one to store the score and the other to see if we need to show the score or not-</p><pre>const [score, setScore] = useState(0);<br>const [showScore, setShowScore] = useState(false);</pre><p>Now we need to create a new function that calculates the score based on the answers-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c75b0c8eb98716bead7726fe0c95180/href">https://medium.com/media/3c75b0c8eb98716bead7726fe0c95180/href</a></iframe><p><strong>Show submit button instead of next on the last question</strong></p><p>In the last question, we will need to show submit instead of next and run the handleSubmitButton function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c1ad79694b96ec62ad30ef3bee41b24/href">https://medium.com/media/1c1ad79694b96ec62ad30ef3bee41b24/href</a></iframe><p>Now if we submit then nothing really happens, so after we submit we should be able to see a screen like this-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Wzls8JdQM13n91d6" /></figure><p>To do this we are going to render the page based on showScore’s value like this-</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21236cce2b5127ffdba44bde326de1b2/href">https://medium.com/media/21236cce2b5127ffdba44bde326de1b2/href</a></iframe><p>Now our app is working completely fine 🥳</p><h3>Giveaway</h3><p>The winner gets the <a href="https://www.jamesqquick.com/courses/react-and-serverless-fullstack-developmnent">React and ServerLess Course</a> course by <a href="https://www.jamesqquick.com/">James Q Quick</a></p><p>To participate in this giveaway</p><ul><li>Make this quiz app better</li><li>Share it on your social media with the hashtag- next-quiz-challenge and don&#39;t forget to tag me :)</li></ul><p><strong>Important Dates</strong></p><ul><li>18th November 2021: Submit your projects before 18th November 12 PM IST.</li><li>20th November 2021: The winner will be announced on my social media.</li></ul><p><strong>Few features you can add-</strong></p><ul><li>Leaderboard</li><li>Show correct and incorrect answers</li><li>Timer</li><li>Improve UI</li></ul><h3>Useful Links</h3><p><a href="https://github.com/avneesh0612/quiz-app">GitHub repository</a></p><p><a href="https://quiz-challenge.vercel.app/">Demo</a></p><p><a href="https://avneesh-links.vercel.app/">All socials</a></p><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f61b14148661" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/build-a-quiz-app-with-next-js-and-tailwindcss-f61b14148661">Build a Quiz App with Next.js and Tailwind CSS</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to add an emoji picker to an input field in react app]]></title>
            <link>https://medium.com/weekly-webtips/how-to-add-an-emoji-picker-to-an-input-field-in-react-app-d41a2966fcc1?source=rss-667e6a1a5d12------2</link>
            <guid isPermaLink="false">https://medium.com/p/d41a2966fcc1</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[emoji]]></category>
            <category><![CDATA[usestate]]></category>
            <category><![CDATA[emoji-picker]]></category>
            <dc:creator><![CDATA[Avneesh Agarwal]]></dc:creator>
            <pubDate>Thu, 22 Jul 2021 13:19:33 GMT</pubDate>
            <atom:updated>2021-07-22T15:32:20.071Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/676/0*yr-JjvnhtRAYK_Em.png" /></figure><h4>Creating a new react app</h4><pre>npx create-react-app </pre><h4>Starting the app -</h4><pre># npm<br>npm start<br># yarn<br>yarn start</pre><h4>Installing the required dependencies -</h4><pre># npm<br>npm install emoji-mart<br># yarn<br>yarn add emoji-mart</pre><h4>Cleanup process</h4><ul><li>Delete everything inside the div in App.js and remove the import of logo.svg on top.</li><li>Delete logo.svg file.</li><li>Delete everything in App.css.</li><li>In index.css add this line of code -</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/898c5a61f840c6921588b9a7edd3057e/href">https://medium.com/media/898c5a61f840c6921588b9a7edd3057e/href</a></iframe><h4>Creating an input</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d254ba84d6a3d7cd700c42a0bc2e06a7/href">https://medium.com/media/d254ba84d6a3d7cd700c42a0bc2e06a7/href</a></iframe><p><strong>Mapping to a state</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da195de8fd546e01b18479e680ab4c40/href">https://medium.com/media/da195de8fd546e01b18479e680ab4c40/href</a></iframe><p><strong>Creating an svg button for emojis</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac32b57beacc2cd369da76f319f974a6/href">https://medium.com/media/ac32b57beacc2cd369da76f319f974a6/href</a></iframe><p><strong>Adding some styles in</strong> <strong><em>App.css</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7c940e86d9322fbaea5cb0a02aa2d18/href">https://medium.com/media/a7c940e86d9322fbaea5cb0a02aa2d18/href</a></iframe><p><strong>Creating a state for showing picker</strong></p><pre>const [showEmojis, setShowEmojis] = useState(false);</pre><p><strong>Attaching it to the onClick of button</strong></p><pre>&lt;button <em>className</em>=&quot;button&quot; <em>onClick</em>={() =&gt; setShowEmojis(!showEmojis)}&gt;</pre><p><strong>Rendering the emoji picker</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/caeb0baf747ba994ab493d261757c3cc/href">https://medium.com/media/caeb0baf747ba994ab493d261757c3cc/href</a></iframe><p>We will import Picker and the CSS like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3301debcf640abc3a8da4975532e0587/href">https://medium.com/media/3301debcf640abc3a8da4975532e0587/href</a></iframe><p><strong>Adding the emojis with the text in the input</strong></p><p>Add an <em>onSelect </em>to the picker</p><pre>&lt;Picker <em>onSelect</em>={addEmoji} /&gt;</pre><p>Create the addEmoji function</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5bd50d6035d628ec1de99631835b9ea5/href">https://medium.com/media/5bd50d6035d628ec1de99631835b9ea5/href</a></iframe><p>Now our emoji picker is working! 🥳</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*ka5WHzc4cT05fApIiRBxeA.png" /></figure><h4>Useful links:</h4><ul><li><a href="https://github.com/avneesh0612/emoji-picker-demo">Github repository</a></li><li><a href="https://reactjs.org/">React docs</a></li><li><a href="https://avneesh-links.vercel.app/">All socials</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d41a2966fcc1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/weekly-webtips/how-to-add-an-emoji-picker-to-an-input-field-in-react-app-d41a2966fcc1">How to add an emoji picker to an input field in react app</a> was originally published in <a href="https://medium.com/weekly-webtips">Webtips</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Authenticate Users with Auth0 in Next.js]]></title>
            <link>https://javascript.plainenglish.io/how-to-authenticate-users-with-auth0-in-next-auth-9c1160ce48a8?source=rss-667e6a1a5d12------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c1160ce48a8</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[auth0]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Avneesh Agarwal]]></dc:creator>
            <pubDate>Thu, 15 Jul 2021 13:46:54 GMT</pubDate>
            <atom:updated>2021-07-15T17:56:30.792Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to Authenticate Users with Auth0 in Next</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZJzTEHw4DxhPMsOFcvH2rw.png" /><figcaption>Next auth + Auth0</figcaption></figure><h4>What is Auth0?</h4><p>Auth0 is an easy-to-implement, adaptable authentication and authorization platform. If you want to follow along with this tutorial, you can create a free Auth0 account <a href="https://auth0.com/signup?utm_source=external-post&amp;utm_medium=link_placement&amp;utm_campaign=devmar-media">here</a>.</p><h4>Setup</h4><p>I am going to set up a new next app with create-next-app.</p><pre>npx create-next-app next-auth0-demo</pre><h4>Cleanup</h4><p>I will delete everything after the Head starting from the main till the footer.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4290e3681f06f30b95bb23e1dc1c629d/href">https://medium.com/media/4290e3681f06f30b95bb23e1dc1c629d/href</a></iframe><p>Install <a href="https://next-auth.js.org/">Next-Auth</a></p><pre>npm i next-auth # npm<br>yarn add next-auth # yarn</pre><h4>Start using Next auth</h4><p>We will first create a folder inside the api folder in pages called auth.</p><p>In that folder create a file called <strong><em>[…nextauth].js</em></strong></p><p>We are going to use auth0 as the provider, so we need three params. So add this snippet of code in your <strong><em>[…nextauth].js</em></strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3ab967e2bac71918ad6cec85873c4ff/href">https://medium.com/media/b3ab967e2bac71918ad6cec85873c4ff/href</a></iframe><p>Now we will finally configure Next Auth in <strong><em>_app.js</em></strong> like this -</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0905f27341482f32c8c0ef44d7720b08/href">https://medium.com/media/0905f27341482f32c8c0ef44d7720b08/href</a></iframe><h4>Setting up an application in Auth0</h4><p><strong>Creating an app</strong></p><ul><li>Sign up to <a href="https://auth0.com/signup?utm_source=external-post&amp;utm_medium=link_placement&amp;utm_campaign=devmar-media">Auth0</a></li><li>Go to applications under the applications tab</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/1*9A3PRBevntLGWtsfLF2RkA.png" /></figure><ul><li>Create a new application</li><li>Select Regular Web Applications and give a name to your app, then click on create.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*FvH_0QNGMo6lQ4YHazAt5Q.png" /></figure><p><strong>Getting the credentials</strong></p><p>In the settings tab copy the domain,client id , and the client secretand add it to your .env.local file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/68c22176572b045df443d96a35a8c2a6/href">https://medium.com/media/68c22176572b045df443d96a35a8c2a6/href</a></iframe><p>We will also add the NEXTAUTH_URL in the env like this</p><pre>NEXTAUTH_URL=http://localhost:3000</pre><h4>Creating a sign-in button</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b40e156e2ce2f7dfac4a2057c718580/href">https://medium.com/media/0b40e156e2ce2f7dfac4a2057c718580/href</a></iframe><p>Now if we try to sign in, we will see this error page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MBJDtKk6psR_fqE7yz_9KA.png" /></figure><p>We need to add <a href="http://localhost:3000/api/auth/callback/auth0">http://localhost:3000/api/auth/callback/auth0</a> as an allowed callback URL and save it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*FNQqO77z4UcZ7Q3Qa96ufw.png" /></figure><p>Now we can sign in successfully!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.loom.com%2Fembed%2Faece79d9d45c47c4bd57c9a22eccb62f&amp;display_name=Loom&amp;url=https%3A%2F%2Fwww.loom.com%2Fshare%2Faece79d9d45c47c4bd57c9a22eccb62f&amp;image=https%3A%2F%2Fcdn.loom.com%2Fsessions%2Fthumbnails%2Faece79d9d45c47c4bd57c9a22eccb62f-00001.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=loom" width="1920" height="1440" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc573c29a1bef1cdb6c3b50dd413bcad/href">https://medium.com/media/cc573c29a1bef1cdb6c3b50dd413bcad/href</a></iframe><h4>Getting user info</h4><p>We will create a function with getServerSidePropswhere we will get our user details via session.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79b664476fe49bb8e2f296759299bb1b/href">https://medium.com/media/79b664476fe49bb8e2f296759299bb1b/href</a></iframe><p>We would like to have a signout button if the user is already signed in. So we will have a sign-in button if there is no user and a signout button if there is a user.</p><p>So create a ternary operator like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d3d32b156b9b67823bb6a51279ae2ca5/href">https://medium.com/media/d3d32b156b9b67823bb6a51279ae2ca5/href</a></iframe><p>And then import everything we need from next-auth/client.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e178f11f6e0f493548985b32bc3c07df/href">https://medium.com/media/e178f11f6e0f493548985b32bc3c07df/href</a></iframe><h4>Showing the user details</h4><p>We are going to add this code to get the user’s email, name, and image.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f438f336ca8e9be83cd7a2c96434e85/href">https://medium.com/media/2f438f336ca8e9be83cd7a2c96434e85/href</a></iframe><p>The final code should be like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e1589a49170e97afec8f21783b6f7119/href">https://medium.com/media/e1589a49170e97afec8f21783b6f7119/href</a></iframe><p>As we are using the Next image, we will need to add the domain in <strong><em>next.config.js</em></strong></p><p>We are using google sign in, so we will add lh3.googleusercontent.com as the domain, if you don’t know the origin of the image you can use the normal img tag instead.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2cc9dd0e81657b90dd93a06f64a0607/href">https://medium.com/media/a2cc9dd0e81657b90dd93a06f64a0607/href</a></iframe><h4>Deployment</h4><p>I will create a new GitHub repository and push the code there. If you don’t about git and GitHub. Check my <a href="https://avneeshagarwal.medium.com/git-and-github-crash-course-b44f4885ff66">Git and Github Crash Course</a>.</p><p>After that go to <a href="https://vercel.com/">Vercel</a></p><ul><li>Sign up with your GitHub</li><li>Click on create a new project</li><li>Import the repository that you created</li><li>Click deploy</li></ul><p>Your site will now be deployed but the authentication won’t work.</p><p>Adding environment variables.</p><ul><li>After the site is deployed go to the dashboard of the current app click on settings and then Environment Variables.</li><li>Add the Auth0 client id, Auth0 client secret, and Auth0 domain which is present in our .env.local file.</li><li>After you add the two it will look like this.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*W2iM_UFXDHpWeo_KRI8tQw.png" /></figure><ul><li>We will add another variable, our Next Auth URL and it will be the deployed URL instead of the localhost.</li><li>To get the URL, click on domains, get the shortest link, and add it to the NEXTAUTH_URL variable. It would be similar to <a href="https://next-auth0-demo.vercel.app/">https://next-auth0-demo.vercel.app/</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*YuQGkhI6y1QSqfSON1IoHg.png" /></figure><ul><li>Finally, go to the Deployments tab on the tab in the header.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/0*zTZu4MU2EkoLwFW9.png" /></figure><ul><li>Click on the latest version and press redeploy.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cXXyCAcdziRcVvhr8ewfMw.png" /></figure><h4>Change the URI in Auth0</h4><p>Finally, replace localhost:3000 with the actual URL and use HTTPS instead of HTTP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*bm37wxIXrN8PTxSMOcLvoA.png" /></figure><p>Our authentication is now working perfectly. Congratulations. You have created your first Auth0 sign-in with Next Auth! 🥳</p><p>If you have found this useful, be sure to let me know in the comments. You can also let me know if you want to see any other kind of authentication.</p><h4>Further resources</h4><ul><li><a href="https://github.com/avneesh0612/next-auth0-demo">Github repository</a></li><li><a href="https://nextjs.org/docs">NextJS docs</a></li><li><a href="https://next-auth.js.org/">Next Auth</a></li><li><a href="https://auth0.com/">Auth0</a></li><li><a href="https://avneesh-links.vercel.app/">All socials</a></li></ul><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c1160ce48a8" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/how-to-authenticate-users-with-auth0-in-next-auth-9c1160ce48a8">Authenticate Users with Auth0 in Next.js</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a Custom Sign-in Page with NextAuth.js]]></title>
            <link>https://javascript.plainenglish.io/how-to-create-a-custom-sign-in-page-in-next-auth-1612dc17beb7?source=rss-667e6a1a5d12------2</link>
            <guid isPermaLink="false">https://medium.com/p/1612dc17beb7</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Avneesh Agarwal]]></dc:creator>
            <pubDate>Sun, 11 Jul 2021 12:45:02 GMT</pubDate>
            <atom:updated>2024-07-16T07:11:22.082Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to create a custom sign-in page with NextAuth.js</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*req3d2PtlPwD058XPXs5KA.png" /></figure><p>Today, we are going to see how to build a custom login page with NextAuth.js.</p><p>In one of my previous articles, we saw what is NextAuth and how to build Google authentication with it. If you haven’t read it already, you can check it out <a href="https://medium.com/geekculture/why-and-how-to-get-started-with-next-auth-61740558b45b">here</a>.</p><h4>Let’s get started</h4><p>In <strong><em>[…nextauth].js</em></strong>, we will add a pages property below providers like this:</p><pre>pages: {<br>signIn: &quot;/signin&quot;,<br>},</pre><p>Now, our<strong> <em>[…nextauth].js</em></strong> should look something like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c27fa7c53c5b8b8f9d18b2ea5ba8638f/href">https://medium.com/media/c27fa7c53c5b8b8f9d18b2ea5ba8638f/href</a></iframe><h4>Creating the sign-in page</h4><p>In the pages directory, we are going to create a new page <strong><em>signin.js</em></strong>.</p><p>We are going to need a bunch of imports from the next-auth/client package. Here are all the imports:</p><pre>import { providers, signIn, getSession, csrfToken } from &quot;next-auth/client&quot;;</pre><p>We will now create a simple React functional component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c45a86fee98ef8359d02e999d5e4dd0/href">https://medium.com/media/3c45a86fee98ef8359d02e999d5e4dd0/href</a></iframe><blockquote><em>💡</em><strong><em> </em>Create a Free AI-Powered Blog on Differ:</strong></blockquote><p><a href="https://differ.blog/differ-ai?utm_campaign=differai-annoucement-sitewide-banner">Introducing DifferAI</a></p><h4>Showing all the providers</h4><p>Inside our component, we are going to map out all the providers in this case we have only Google sign-in.</p><p>We first need to get all the providers, we are going to use getServerSideProps to get all the providers:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d098a0217f979dacee0c2e78d05e532/href">https://medium.com/media/9d098a0217f979dacee0c2e78d05e532/href</a></iframe><p>This is going to give us all the providers we have added in <strong><em>[…nextauth].js</em></strong> and we are going to receive the providers as a prop.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/501466f4918e8517bc217323ae60542a/href">https://medium.com/media/501466f4918e8517bc217323ae60542a/href</a></iframe><p>This is going to give us a simple button saying <strong>‘Sign in with Google’</strong>. If we click on this button our sign-in flow should still work properly. Now if we sign in, we will be redirected to the sign-in page and not the home page.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.loom.com%2Fembed%2F3af7cf2fff9846b282b52630a1307f48&amp;display_name=Loom&amp;url=https%3A%2F%2Fwww.loom.com%2Fshare%2F3af7cf2fff9846b282b52630a1307f48&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=loom" width="1280" height="960" frameborder="0" scrolling="no"><a href="https://medium.com/media/7534cb1e0e943ad4268da470cb578b04/href">https://medium.com/media/7534cb1e0e943ad4268da470cb578b04/href</a></iframe><p>We will now see how to fix this.</p><p>In the getServerSideProps function we are going to add this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9153b66de668a59b0419c60ff92929d4/href">https://medium.com/media/9153b66de668a59b0419c60ff92929d4/href</a></iframe><p>Now if we sign in, we will be redirected to the home page, if you want to redirect the user to some other page change the location in the destination.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.loom.com%2Fembed%2Fef2ca50af39f43a6a1dfa5965d6d605a&amp;display_name=Loom&amp;url=https%3A%2F%2Fwww.loom.com%2Fshare%2Fef2ca50af39f43a6a1dfa5965d6d605a&amp;image=https%3A%2F%2Fcdn.loom.com%2Fsessions%2Fthumbnails%2Fef2ca50af39f43a6a1dfa5965d6d605a-1626006023426.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=loom" width="1280" height="960" frameborder="0" scrolling="no"><a href="https://medium.com/media/80b060c08d5613f7524574d14341c9f1/href">https://medium.com/media/80b060c08d5613f7524574d14341c9f1/href</a></iframe><p>The final <em>signin.js</em> looks like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5cd70d8b3b445a62352372a71567a092/href">https://medium.com/media/5cd70d8b3b445a62352372a71567a092/href</a></iframe><h4>Styling the page</h4><p>Now I am going to apply some simple stylings to the button and center it. I am going to use CSS modules for the styles as it is built-in, you can use anything you like.</p><ul><li>Create a file <strong><em>Signin.module.css</em></strong></li></ul><p>I will add a className to the container div and the button like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40b632eb61caa67549c91c14bc3229c7/href">https://medium.com/media/40b632eb61caa67549c91c14bc3229c7/href</a></iframe><p>We will import styles from <strong><em>Signin.module.css</em></strong> like this</p><pre>import styles from &quot;../styles/Signin.module.css&quot;;</pre><ul><li>Finally, we will add the styles in <strong><em>Signin.module.css</em></strong> to make it look good</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/55bd6a3a451cd2d7b6c8f1cc3950c373/href">https://medium.com/media/55bd6a3a451cd2d7b6c8f1cc3950c373/href</a></iframe><p>After applying these styles we get a centered, good-looking button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/196/1*RaxVebm8duCO27DgBtMspQ.png" /></figure><p>I hope you could create your first custom sign-in page with Next auth.</p><p><strong>Useful links:</strong></p><p><a href="https://github.com/avneesh0612/next-auth-custom-login">Github repository</a></p><p><a href="https://nextjs.org/docs">NextJS docs</a></p><p><a href="https://next-auth.js.org/">Next auth</a></p><p><a href="https://avneesh-links.vercel.app/">All socials</a></p><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://twitter.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a></li><li>Visit our other platforms: <a href="https://cofeed.app/"><strong>CoFeed</strong></a> | <a href="https://differ.blog/"><strong>Differ</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1612dc17beb7" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/how-to-create-a-custom-sign-in-page-in-next-auth-1612dc17beb7">Create a Custom Sign-in Page with NextAuth.js</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to make a Next.js app a PWA]]></title>
            <link>https://medium.com/geekculture/how-to-make-a-next-js-app-a-pwa-a5e2b13da548?source=rss-667e6a1a5d12------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5e2b13da548</guid>
            <category><![CDATA[pwa-development]]></category>
            <category><![CDATA[next]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[pwa]]></category>
            <category><![CDATA[nextjs]]></category>
            <dc:creator><![CDATA[Avneesh Agarwal]]></dc:creator>
            <pubDate>Wed, 07 Jul 2021 13:43:43 GMT</pubDate>
            <atom:updated>2021-07-09T07:22:01.242Z</atom:updated>
            <content:encoded><![CDATA[<p>Today we are going to see how to make a Next.js app a Progressive Web App</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FcvmmciAIUhpF1t-9IO8fQ.jpeg" /></figure><h3>Creating a Next app</h3><pre>npx create-next-app next-pwa-demo</pre><p>I am going to convert the default Next.js template into a PWA, you can convert your own web app.</p><h4>Installing the required dependency</h4><pre>npm i next-pwa # npm<br>yarn add next-pwa # yarn</pre><h4>Getting the icons for the app</h4><p>We are going to need a 512x512 and a 192x192 icon. Add these two icons in the pubic directory.</p><h4>Creating a manifest</h4><p>Inside the public directory create a file name manifest.json. You can use a manifest creator but I have created my manifest, so you can copy that as well.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab8275a0fc3f1eaad64f2744a17e5067/href">https://medium.com/media/ab8275a0fc3f1eaad64f2744a17e5067/href</a></iframe><h4>Creating _document.js page</h4><p>We will now create a _document.js file inside our pages folder.</p><p>Now we will add this code in the file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1961157116b4fab97d8a3609fc967386/href">https://medium.com/media/1961157116b4fab97d8a3609fc967386/href</a></iframe><h4>Finallizing the PWA in next.config.js</h4><p>We are now going to create a next.config.js file in the root of our directory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b6d09db5dba065b76f35a3f48b8cf8f/href">https://medium.com/media/9b6d09db5dba065b76f35a3f48b8cf8f/href</a></iframe><p>This is going to create our progressive web app.</p><h4>How to check if it is a PWA</h4><p>In the top left corner of the tab, you will be able to see an install button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MiFAzP50FL9DWSNz4e3bQg.png" /></figure><p>Now if you click on install an app will get installed and popup.</p><p>Congratulations 🥳! You have successfully created your 1st Progressive Web App(PWA) ✌</p><p>Useful links -</p><p><a href="https://github.com/avneesh0612/next-pwa-demo">Github repository</a></p><p><a href="https://nextjs.org/docs">NextJS docs</a></p><p><a href="https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps">PWA docs</a></p><p><a href="https://avneesh-links.vercel.app/">All socials</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5e2b13da548" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/how-to-make-a-next-js-app-a-pwa-a5e2b13da548">How to make a Next.js app a PWA</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[How to handle click outside a div in React with a custom hook]]></title>
            <link>https://medium.com/geekculture/how-to-handle-click-outside-a-div-in-react-d2283dc4ed57?source=rss-667e6a1a5d12------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2283dc4ed57</guid>
            <category><![CDATA[custom-hook]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[dropdown]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[drop-down-menu]]></category>
            <dc:creator><![CDATA[Avneesh Agarwal]]></dc:creator>
            <pubDate>Thu, 24 Jun 2021 09:10:10 GMT</pubDate>
            <atom:updated>2021-06-26T06:52:53.773Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gP2cJtJUYudbNBBd.png" /></figure><p>This is a very important thing, especially when creating dropdowns. The user expects the dropdown to close when they click outside the dropdown. So we are going to see how can we do that.</p><h3>Creating a new react app</h3><p>Prerequisites for creating a react app-</p><ul><li><a href="https://nodejs.org/">Node.js</a> (Latest version recommended)</li></ul><p>After Node is installed you need to run the following command-</p><pre>npx create-react-app handle-click-demo # you can name it anything you want</pre><h3>Starting the app -</h3><pre># npm<br>npm start<br># yarn<br>yarn start</pre><h3>Cleanup process</h3><ul><li>Delete everything inside the div in App.js and remove the import of logo.svg on top.</li><li>Delete App.test.js, SetupTests.js, logo.svg files.</li><li>Delete everything in App.css.</li><li>In index.css add this line on the top-</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7872e54a3dd78958386452f4660fa650/href">https://medium.com/media/7872e54a3dd78958386452f4660fa650/href</a></iframe><p>We are going to create our own dropdown instead of using the select tag.</p><h4>Creating a dropdown</h4><p>We will create a button to open and close the dropdown.</p><pre>&lt;button&gt;Open&lt;/button&gt;</pre><p>We can see this button on the top left part of the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/65/1*hbb8ulVWkQi2L4tI37G2jQ.png" /></figure><p>Now we will create a state which will check if the dropdown is open or closed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f43c175d48d1312c9fe284b125582be3/href">https://medium.com/media/f43c175d48d1312c9fe284b125582be3/href</a></iframe><p>Now we will add an onClick event on the button.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e43d8bd481413fe01bdf509f09670a0a/href">https://medium.com/media/e43d8bd481413fe01bdf509f09670a0a/href</a></iframe><p>We will change the text of the button if the state is true or false with a ternary operator.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6dbcf020bd5be8aec205aaee1fc7018/href">https://medium.com/media/a6dbcf020bd5be8aec205aaee1fc7018/href</a></iframe><p>Finally, we will create the dropdown.</p><p>I have created a simple dropdown below the button that has 3 options.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c8f44aecf182f278d0aeb688072b3afe/href">https://medium.com/media/c8f44aecf182f278d0aeb688072b3afe/href</a></iframe><p>I have applied some basic stylings to the dropdown and the app div to center the elements.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b210ea1ab59f50f75936dd18757bab1/href">https://medium.com/media/5b210ea1ab59f50f75936dd18757bab1/href</a></iframe><h4>Rendering the dropdown based onClick of the button</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5df7d765cce922f25ac062bb8455c080/href">https://medium.com/media/5df7d765cce922f25ac062bb8455c080/href</a></iframe><p>What this code is doing is, if the isOpen is true then show dropdown otherwise show nothing.</p><p>But this has a problem, if you click outside the div the dropdown won’t close.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.loom.com%2Fembed%2F928ea0debde140188348980a710cf94e&amp;display_name=Loom&amp;url=https%3A%2F%2Fwww.loom.com%2Fshare%2F928ea0debde140188348980a710cf94e&amp;image=https%3A%2F%2Fcdn.loom.com%2Fsessions%2Fthumbnails%2F928ea0debde140188348980a710cf94e-00001.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=loom" width="1280" height="960" frameborder="0" scrolling="no"><a href="https://medium.com/media/a4c9c47cb263ad7da02a64f6947a6ce5/href">https://medium.com/media/a4c9c47cb263ad7da02a64f6947a6ce5/href</a></iframe><h4>Creating a custom hook</h4><p>We will create a custom hook called useComponentVisible. So create a file useComponentVisible.js inside the src directory and add this snippet of code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48e1396f9e52a01c2c0be95c2a9a5aa0/href">https://medium.com/media/48e1396f9e52a01c2c0be95c2a9a5aa0/href</a></iframe><p>This code is using the state and doing a similar thing that we did while creating the dropdown. Then it is adding and removing the Event listener.</p><h4>Using the custom hook</h4><p>Now we will use the custom hook inside of our app.</p><p>Calling the hook. We will replace the useState with this. This will give some errors for now.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0614c708f5688056aec7961e8bc5bcfb/href">https://medium.com/media/0614c708f5688056aec7961e8bc5bcfb/href</a></iframe><p>Importing the hook.</p><pre>import useComponentVisible from &quot;./useComponentVisible&quot;;</pre><p>Now we will attach the ref to the button and dropdown container as we want the dropdown to close when we click elsewhere.</p><p>We will change isOpen to isComponentVisible and setisOpen to setIsComponentVisible like this -</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e96caf1815b7451547d081d96fa9ef4f/href">https://medium.com/media/e96caf1815b7451547d081d96fa9ef4f/href</a></iframe><p>Now are dropdown is working perfectly.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.loom.com%2Fembed%2F1e8f4e3b96d64e7abc39521b739af0e5&amp;display_name=Loom&amp;url=https%3A%2F%2Fwww.loom.com%2Fshare%2F1e8f4e3b96d64e7abc39521b739af0e5&amp;image=https%3A%2F%2Fcdn.loom.com%2Fsessions%2Fthumbnails%2F1e8f4e3b96d64e7abc39521b739af0e5-00001.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=loom" width="1280" height="960" frameborder="0" scrolling="no"><a href="https://medium.com/media/7d023174c1cd091b776dc7e9705672a0/href">https://medium.com/media/7d023174c1cd091b776dc7e9705672a0/href</a></iframe><p>Hope you learned from this tutorial. Let me know what you want to see next. ✌</p><p>Useful links -</p><p><a href="https://github.com/avneesh0612/handle-click-outside-div">Github repository</a></p><p><a href="https://reactjs.org/">ReactJS docs</a></p><p><a href="https://avneesh-links.vercel.app/">All socials</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2283dc4ed57" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/how-to-handle-click-outside-a-div-in-react-d2283dc4ed57">How to handle click outside a div in React with a custom hook</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[Why and how to get started with Next auth?]]></title>
            <link>https://medium.com/geekculture/why-and-how-to-get-started-with-next-auth-61740558b45b?source=rss-667e6a1a5d12------2</link>
            <guid isPermaLink="false">https://medium.com/p/61740558b45b</guid>
            <category><![CDATA[nextauth]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[authentication]]></category>
            <dc:creator><![CDATA[Avneesh Agarwal]]></dc:creator>
            <pubDate>Tue, 15 Jun 2021 08:57:05 GMT</pubDate>
            <atom:updated>2021-07-19T10:51:51.619Z</atom:updated>
            <content:encoded><![CDATA[<p>Google authentication with Next.js</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DuTXEz3ArM1x6rfM" /></figure><h4>Why should you choose Next auth?</h4><p>You might be wondering, if you are already using something like firebase then why should you use Next auth? Here’s why</p><ul><li>Easy to use</li><li>Gives us a lot of providers for authentication</li><li>You can get the details as soon as the user reaches the page with serverSideProps while you would get the user&#39;s details after a few seconds with something like firebase.</li><li>It is very secure as it uses HTTP POST + CSRF Token validation<br>JWT with JWS / JWE / JWK / JWK</li></ul><h4>Setup</h4><p>I am going to set up a new next app with create-next-app.</p><pre>npx create-next-app next-auth-demo</pre><p>Cleanup</p><p>I will delete everything after the Head starting from the main till the footer.</p><p>Install next-auth</p><pre>npm i next-auth # npm<br>yarn add next-auth # yarn</pre><h4>Start using Next auth</h4><p>We will first create a folder inside the api folder in pages called auth.</p><p>In that folder create a file called […nextauth].js</p><p>We are going to start with Google authentication. So add this snippet of code in your […nextauth].js.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/66083c9dcbe322a57c1b8fd327b15ce6/href">https://medium.com/media/66083c9dcbe322a57c1b8fd327b15ce6/href</a></iframe><p>Now we will finally configure Next auth in _app.js like this -</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1fa77eb0341daf6d95b90027052a3cb8/href">https://medium.com/media/1fa77eb0341daf6d95b90027052a3cb8/href</a></iframe><h4>Google Authentication</h4><p>We are going to use firebase to create the credentials for us. We can use Google cloud console directly but we will need to configure extra stuff.</p><p>Go to <a href="https://console.firebase.google.com/u/0/">firebase</a>. Create a new account then click on add project.</p><p>Give a name for your app then you can leave everything as default and click next.</p><p>Go to the authentication tab in the sidebar. Click get started. Click on Google sign in and enable it. Now simply click on save.</p><p>If you click on edit again and open the Web SDK configuration accordion. You can see the credentials we need. I am showing my credentials for the demo but you shouldn’t show your credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*2esJhM2Gl9HMcaTfpiprLg.png" /></figure><p>Now we will create a new file called .env.local in the root of our folder. In this file, we will create two environment variables called GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET.</p><p>Now copy-paste the client id and secret here.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5624220f41ae6c3aac1938c9c95e91c4/href">https://medium.com/media/5624220f41ae6c3aac1938c9c95e91c4/href</a></iframe><p>We will create another variable called NEXTAUTH_URL which will be our app URL which in development will be our localhost.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/32b8cb4d8cc7233b162623684706caa4/href">https://medium.com/media/32b8cb4d8cc7233b162623684706caa4/href</a></iframe><p>After adding the variables make sure to restart the server.</p><p>We will create a Sign-in button in index.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be6d6bd8cb350fb28d467798c3a5834b/href">https://medium.com/media/be6d6bd8cb350fb28d467798c3a5834b/href</a></iframe><p>Now if we click on the Sign-in button it will show an error similar to this</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.loom.com%2Fembed%2Ffe4a44daff1e40788d45ade8885cda5c&amp;display_name=Loom&amp;url=https%3A%2F%2Fwww.loom.com%2Fshare%2Ffe4a44daff1e40788d45ade8885cda5c&amp;image=https%3A%2F%2Fcdn.loom.com%2Fsessions%2Fthumbnails%2Ffe4a44daff1e40788d45ade8885cda5c-00001.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=loom" width="1280" height="960" frameborder="0" scrolling="no"><a href="https://medium.com/media/f0913fb545c4ef1f7d1f752671057c8a/href">https://medium.com/media/f0913fb545c4ef1f7d1f752671057c8a/href</a></iframe><p>Now copy the link at which is at the bottom of the error and paste the link into a new tab. Scroll down and you will be able to see redirect URI’s.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*FRv1AgDrMRTDbHO06hhgGw.png" /><figcaption>Redirect URIs</figcaption></figure><p>Now click on ADD URI and add this</p><pre> <a href="http://localhost:3000/api/auth/callback/google">http://localhost:3000/api/auth/callback/google</a></pre><p>Then click on save. If you try logging in. You can now log in.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.loom.com%2Fembed%2Fffcf42de3ad14047a55c1454b9d23a9c&amp;display_name=Loom&amp;url=https%3A%2F%2Fwww.loom.com%2Fshare%2Fffcf42de3ad14047a55c1454b9d23a9c&amp;image=https%3A%2F%2Fcdn.loom.com%2Fsessions%2Fthumbnails%2Fffcf42de3ad14047a55c1454b9d23a9c-00001.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=loom" width="1280" height="960" frameborder="0" scrolling="no"><a href="https://medium.com/media/ffc311569da0846531cf5de09f363505/href">https://medium.com/media/ffc311569da0846531cf5de09f363505/href</a></iframe><h4>Getting user info</h4><p>We will first fetch the data on the client then we will see how to fetch it with serverSideProps.</p><p>For fetching the user’s info on the client we will use the useSession hook.</p><p>The useSession hook gives us an object of session which has the user’s info inside it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5af8fe7a948ab95004e6776aa0ec4b20/href">https://medium.com/media/5af8fe7a948ab95004e6776aa0ec4b20/href</a></iframe><p>Now let’s see what we get back on signing in</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.loom.com%2Fembed%2Fdab1534a409e424391605c93046ac870&amp;display_name=Loom&amp;url=https%3A%2F%2Fwww.loom.com%2Fshare%2Fdab1534a409e424391605c93046ac870&amp;image=https%3A%2F%2Fcdn.loom.com%2Fsessions%2Fthumbnails%2Fdab1534a409e424391605c93046ac870-00001.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=loom" width="1280" height="960" frameborder="0" scrolling="no"><a href="https://medium.com/media/6ec772ea04dede4a3beb2500abadf2aa/href">https://medium.com/media/6ec772ea04dede4a3beb2500abadf2aa/href</a></iframe><p>We would like to have a signout button if the user is already signed in. So we will have a sign-in button if there is no user and a signout button if there is a user.</p><p>So create a ternary operator like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc5e080faacfb271d079df4a4f25bcc8/href">https://medium.com/media/bc5e080faacfb271d079df4a4f25bcc8/href</a></iframe><p>And then import signOut from next-auth/client.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/935f4e7198d708438899990d35d0aa4e/href">https://medium.com/media/935f4e7198d708438899990d35d0aa4e/href</a></iframe><h4>Fetching the user data on the server</h4><p>We will create a function with serverSideProps where we will get our user details via session.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79b664476fe49bb8e2f296759299bb1b/href">https://medium.com/media/79b664476fe49bb8e2f296759299bb1b/href</a></iframe><p>Instead of importing useSession, we will import getSession from next-auth/client</p><pre>import { getSession, signIn, signOut } from &quot;next-auth/client&quot;;</pre><p>It will now fetch the data instantly without the delay.</p><h4>Deployment</h4><p>I will create a new GitHub repository and push the code there. If you don’t about git and GitHub. Check my <a href="https://avneeshagarwal.medium.com/git-and-github-crash-course-b44f4885ff66">Git and Github Crash Course</a>.</p><p>After that go to <a href="https://vercel.com/">Vercel</a></p><ul><li>Sign up with your GitHub</li><li>Click on create a new project</li><li>Import the repository that you created</li><li>Click deploy</li></ul><p>Your site will now be deployed but the authentication won’t work.</p><p>Adding environment variables.</p><ul><li>After the site is deployed go to the dashboard of the current app click on settings and then Environment Variables.</li><li>Add the Google client id and Google client secret which is present in our .env.local file.</li><li>After you add the two it will look like this.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*R1Red506lKDMk_QD9tqe_Q.png" /></figure><ul><li>We will add another variable which is our next auth URL and it will be the deployed URL instead of the localhost.</li><li>To get the URL click on domains and get the shortest link and add it to the NEXTAUTH_URL variable. It would be similar to <a href="https://next-auth-demo-lemon.vercel.app/">https://next-auth-demo-lemon.vercel.app/</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dzink2UGLy_bnjLpb2mvJA.png" /></figure><ul><li>Finally, go to the Deployments tab on the tab in the header.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*IthJ2R0mArpwRmN4VTFvpg.png" /></figure><ul><li>Click on the latest version and press redeploy.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q3CtaQoRaxCV4s7m6jjC3A.png" /></figure><h4>Adding the URI to Google</h4><p>After you redeploy try signing in again and it will show you an error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*6s_4D8W1rPeLdK-tJCFFKA.png" /></figure><ul><li>Go to the URL at the bottom of the error.</li><li>Create a new URI and paste the link after ‘The redirect URI in the request’ which is <a href="https://next-auth-demo-lemon.vercel.app/api/auth/callback/google">https://next-auth-demo-lemon.vercel.app/api/auth/callback/google</a> in my case.</li></ul><p>Our authentication is now working perfectly</p><p>Congratulations 🥳. You have created your first Google Sign-in with Next auth. If you wanna customize the login page click <a href="https://javascript.plainenglish.io/how-to-create-a-custom-sign-in-page-in-next-auth-1612dc17beb7">here</a>. If you wanna add Auth0 authentication click <a href="https://javascript.plainenglish.io/how-to-authenticate-users-with-auth0-in-next-auth-9c1160ce48a8">here</a>.</p><p>Let me know if you want to see any other kind of authentication😉.</p><p>Useful links -</p><p><a href="https://github.com/avneesh0612/next-auth-demo">Github repository</a></p><p><a href="https://nextjs.org/docs">NextJS docs</a></p><p><a href="https://next-auth.js.org/">Next auth</a></p><p><a href="https://avneesh-links.vercel.app/">All socials</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61740558b45b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/why-and-how-to-get-started-with-next-auth-61740558b45b">Why and how to get started with Next 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>