<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vincent Dizon</title>
    <description>The latest articles on DEV Community by Vincent Dizon (@vncntdzn).</description>
    <link>https://dev.to/vncntdzn</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F203928%2F89c8022c-fe4d-4783-beff-753619ea99e4.jpg</url>
      <title>DEV Community: Vincent Dizon</title>
      <link>https://dev.to/vncntdzn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vncntdzn"/>
    <language>en</language>
    <item>
      <title>Personalizing MUI Stepper</title>
      <dc:creator>Vincent Dizon</dc:creator>
      <pubDate>Thu, 27 Jul 2023 15:42:30 +0000</pubDate>
      <link>https://dev.to/vncntdzn/personalizing-mui-stepper-56dh</link>
      <guid>https://dev.to/vncntdzn/personalizing-mui-stepper-56dh</guid>
      <description>&lt;p&gt;Interested on how to customize your MUI Stepper?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Stepper activeStep={activeStep}&amp;gt;
  &amp;lt;Step
    sx={{
      '&amp;amp; .MuiStepLabel-root .Mui-completed': {
        color: 'green', // circle color (COMPLETED)
      },
      '&amp;amp; .MuiStepLabel-label.Mui-completed': {
        color: 'black !important', // label color (COMPLETED)
      },
    }}
  &amp;gt;
    &amp;lt;StepLabel&amp;gt;Personal Details&amp;lt;/StepLabel&amp;gt;
  &amp;lt;/Step&amp;gt;
  &amp;lt;Step
    sx={{
      '&amp;amp; .MuiStepLabel-root .Mui-completed': {
        color: 'green', // circle color (COMPLETED)
      },
      '&amp;amp; .MuiStepLabel-label.Mui-completed': {
        color: 'black !important', // label color (COMPLETED)
      },
    }}
  &amp;gt;
    &amp;lt;StepLabel&amp;gt;Personal Details&amp;lt;/StepLabel&amp;gt;
  &amp;lt;/Step&amp;gt;
&amp;lt;/Stepper&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;from this default view&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N_Owg442--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e4eusgyzznz1qmbdqr4q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N_Owg442--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e4eusgyzznz1qmbdqr4q.png" alt="Default style" width="677" height="187"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;to this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--twK647F---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eomqqu95ym0w9r8hhzfj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--twK647F---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eomqqu95ym0w9r8hhzfj.png" alt="New Style" width="690" height="179"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>materialui</category>
      <category>styling</category>
    </item>
    <item>
      <title>Mastering Authentication in Next.js 13: A Comprehensive Guide to Secure User Authentication</title>
      <dc:creator>Vincent Dizon</dc:creator>
      <pubDate>Thu, 01 Jun 2023 14:08:05 +0000</pubDate>
      <link>https://dev.to/vncntdzn/authentication-in-nextjs13-4egl</link>
      <guid>https://dev.to/vncntdzn/authentication-in-nextjs13-4egl</guid>
      <description>&lt;h2&gt;
  
  
  How to use NextAuth in NextJS 13?
&lt;/h2&gt;

&lt;p&gt;Hey folks,&lt;/p&gt;

&lt;p&gt;On this tutorial, I will teach you how to implement NextAuth in NextJS13.&lt;/p&gt;

&lt;h3&gt;
  
  
  Here are the steps we need to do:
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- Install NextAuth
- Create env file
- Create a google api key clientId and clientSecret
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Install &lt;a href="https://next-auth.js.org/" rel="noopener noreferrer"&gt;NextAuth&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;npm i next-auth&lt;/code&gt; or &lt;code&gt;yarn add next-auth&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Create a google api keys
&lt;/h3&gt;

&lt;p&gt;Create a google keys by going to &lt;a href="https://console.developers.google.com/apis/credentials" rel="noopener noreferrer"&gt;google developers&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;or by following this &lt;a href="https://next-auth.js.org/providers/google" rel="noopener noreferrer"&gt;official tutorial&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Create env file
&lt;/h3&gt;

&lt;p&gt;Create env file in the same level as your app directory and add the keys to it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxipbcle9nm6j5zqchz84.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxipbcle9nm6j5zqchz84.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Code Implementation
&lt;/h3&gt;

&lt;p&gt;Once done, we can start the fun part!&lt;br&gt;
Create api\auth[...nextauth] folder inside the app directory. After that create a file called &lt;code&gt;route.ts&lt;/code&gt;. Your folder should look like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5lavhsjkohrnc0l6pcvy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5lavhsjkohrnc0l6pcvy.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and paste this code&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import NextAuth from "next-auth";
import GoogleProvider from "next-auth/providers/google";
/*
    Note: No secret provided since it's provided in .env.local
    read more: https://next-auth.js.org/configuration/options#secret

*/
const handler = NextAuth({
  // Configure one or more authentication providers
  providers: [
    GoogleProvider({
      clientId: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID!,
      clientSecret: process.env.NEXT_PUBLIC_GOOGLE_CLIENT_SECRET!,
    }),
  ],
  session: {
    maxAge: 60 * 60, // 1 hour
  },
});
export { handler as GET, handler as POST };

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we're done implementing our next auth route. The next step will be implementing our SessionProvider.&lt;/p&gt;

&lt;h3&gt;
  
  
  SessionProvider
&lt;/h3&gt;

&lt;p&gt;Now go to your &lt;code&gt;layout.tsx&lt;/code&gt; file and add SessionProvider from NextAuth.&lt;/p&gt;

&lt;p&gt;Your code should look like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'use client'
import { SessionProvider } from "next-auth/react";
import { Poppins } from "next/font/google";
import "normalize.css";
const inter = Poppins({
  weight: ["300", "500", "600", "700"],
  subsets: ["latin"],
});

export const metadata = {
  title: "Sneak",
  description: "Generated by create next app",
};

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    &amp;lt;html lang="en"&amp;gt;
      &amp;lt;body className={inter.className}&amp;gt;
        &amp;lt;SessionProvider&amp;gt;
          &amp;lt;main&amp;gt;{children}&amp;lt;/main&amp;gt;
        &amp;lt;/SessionProvider&amp;gt;
      &amp;lt;/body&amp;gt;
    &amp;lt;/html&amp;gt;
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Page
&lt;/h3&gt;

&lt;p&gt;Now we will implement the signIn and signOut functions. Go to your page.tsx and copy this code. We will also check if the user is authenticated or not&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client";

import { signIn, signOut, useSession } from "next-auth/react";

const Home = () =&amp;gt; {
  const { data: session, status } = useSession();

  const handleSignin = () =&amp;gt; {
    signIn("google");
  };

  const handleSignout = () =&amp;gt; {
    signOut();
  };
  // this if condition will check if the user is authenticated or not
  if (status === "authenticated") {
    return (
      &amp;lt;div&amp;gt;
        &amp;lt;h1&amp;gt;{session.user?.email}&amp;lt;/h1&amp;gt;
        &amp;lt;button onClick={handleSignout}&amp;gt;Logout&amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
    );
  }
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;button onClick={handleSignin}&amp;gt;Login Button&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default Home;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Aaaaaaaand we're done!&lt;/p&gt;

&lt;h3&gt;
  
  
  Bonus! NextAuth with Middleware
&lt;/h3&gt;

&lt;p&gt;What is middleware? Middleware will run before any page is rendered on the browser. It means, we can protect our pages from unauthorize users.&lt;/p&gt;

&lt;p&gt;Create a &lt;code&gt;middleware.ts&lt;/code&gt; file with the same level as your app.&lt;/p&gt;

&lt;p&gt;It should look like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgg59g3t2eqe7utaaksxi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgg59g3t2eqe7utaaksxi.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, inside the middleware file, paste this code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export { default } from "next-auth/middleware";

// this code will protect any attempts from unauthorize users that will try to access protected route.
export const config = { matcher: ["/protected/:path*"] };

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Any unauthorize users will be force to signIn using their Google Accounts.&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>nextjs</category>
      <category>auth</category>
    </item>
  </channel>
</rss>
