Desishub Lessons
Next JS and TypeScript
Authentication Pages

Authentication Pages with Logic

Start by Creating a auth group and add all the auth Pages as shown below

  • Register Page

    import LoginForm from "@/components/frontend/LoginForm";
    import RegisterForm from "@/components/frontend/RegisterForm";
    import { Lock, Mail } from "lucide-react";
    import Link from "next/link";
    import React from "react";
     
    export default function page() {
    return (
    <section>
      <div className="md:container px-4 md:px-0">
        <div className="border-gray-200 dark:border-gray-700 max-w-xl mx-auto border my-3 shadow rounded-md ">
          <RegisterForm />
        </div>
      </div>
    </section>
    );
    }

    Login Page

    import LoginForm from "@/components/frontend/LoginForm";
    import { authOptions } from "@/config/authOptions";
    import { Lock, Mail } from "lucide-react";
    import { getServerSession } from "next-auth";
    import Link from "next/link";
    import { redirect } from "next/navigation";
    import React from "react";
     
    export default async function page() {
    const session = await getServerSession(authOptions);
    if (session) {
    redirect("/dashboard");
    }
    return (
    <section>
      <div className="md:container px-4 md:px-0">
        <div className="border-gray-200 dark:border-gray-700 max-w-md mx-auto border my-3 shadow rounded-md ">
          <LoginForm />
        </div>
      </div>
    </section>
    );
    }