From 52eeb807667b0210dd51962836576cee7a95dbf3 Mon Sep 17 00:00:00 2001 From: TajwarSaiyeed Date: Thu, 4 Jan 2024 11:57:51 +0600 Subject: [PATCH] sign in page forget password function and demo user data added --- app/(auth)/signin/page.tsx | 363 ++++++++++++++++++++----------------- 1 file changed, 192 insertions(+), 171 deletions(-) diff --git a/app/(auth)/signin/page.tsx b/app/(auth)/signin/page.tsx index 77edba6..8ae7306 100644 --- a/app/(auth)/signin/page.tsx +++ b/app/(auth)/signin/page.tsx @@ -1,194 +1,215 @@ -"use client" +"use client"; -import {useState} from "react"; +import { useState } from "react"; import toast from "react-hot-toast"; import Loader from "@/app/components/Loader/Loader"; -import {useSession, signIn} from "next-auth/react"; -import {redirect, useRouter} from "next/navigation"; -import LockOutlinedIcon from '@mui/icons-material/LockOutlined'; -import {createTheme, ThemeProvider} from '@mui/material/styles'; -import {FieldValues, SubmitHandler, useForm} from "react-hook-form"; -import {Grid, Link, Avatar, Button, CssBaseline, TextField, Box, Typography, Container} from '@mui/material/'; +import { useSession, signIn } from "next-auth/react"; +import { redirect, useRouter } from "next/navigation"; +import LockOutlinedIcon from "@mui/icons-material/LockOutlined"; +import { createTheme, ThemeProvider } from "@mui/material/styles"; +import { FieldValues, SubmitHandler, useForm } from "react-hook-form"; +import { + Grid, + Link, + Avatar, + Button, + CssBaseline, + TextField, + Box, + Typography, + Container, +} from "@mui/material/"; const defaultTheme = createTheme(); export default function SignInPage() { - const [isSubmitting, setIsSubmitting] = useState(false); + const [isSubmitting, setIsSubmitting] = useState(false); - const [testUser, setTestUser] = useState<{ - email: string, - password: string - }>({ - email: "", - password: "" - }) - - const {status} = useSession(); - - const { - register, - handleSubmit, - formState: {errors}, - } = useForm({ - defaultValues: { - email: "", - password: "", - }, - }); - const router = useRouter(); + const [testUser, setTestUser] = useState<{ + email: string; + password: string; + }>({ + email: "", + password: "", + }); - const handleSignIn: SubmitHandler = (data) => { - setIsSubmitting(true); - signIn("credentials", { - ...data, - redirect: false, - }).then((callback) => { - if (callback?.ok && callback?.error === undefined) { - toast.success("Logged in successfully!"); - router.refresh(); - } + const { status } = useSession(); - if (callback?.error) { - toast.error(callback.error); - } - }).finally(() => { - setIsSubmitting(false) - }) - }; + const { + register, + handleSubmit, + formState: { errors }, + } = useForm({ + defaultValues: { + email: "", + password: "", + }, + }); + const router = useRouter(); - if (status === "loading") { - return ; - } + const handleSignIn: SubmitHandler = (data) => { + setIsSubmitting(true); + signIn("credentials", { + ...data, + redirect: false, + }) + .then((callback) => { + if (callback?.ok && callback?.error === undefined) { + toast.success("Logged in successfully!"); + router.refresh(); + } - if (status === "authenticated") { - return redirect("/"); - } + if (callback?.error) { + toast.error(callback.error); + } + }) + .finally(() => { + setIsSubmitting(false); + }); + }; - return ( - - - - - - - - - Sign in - - - + if (status === "loading") { + return ; + } - + if (status === "authenticated") { + return redirect("/"); + } - - - + return ( + + + + + + + + + Sign in + + + - {/**/} - {/* {*/} - {/* setTestUser({*/} - {/* email: "rjabid36@gmail.com",*/} - {/* password: '123456Abid'*/} - {/* })*/} - {/* }}*/} - {/* size={'small'}*/} - {/* variant="contained"*/} - {/* >*/} - {/* Role as Admin*/} - {/* */} - {/* {*/} - {/* setTestUser({*/} - {/* email: "test1@gmail.com",*/} - {/* password: '123456Abid'*/} - {/* })*/} - {/* }}*/} - {/* size={'small'}*/} - {/* variant="contained"*/} - {/* >*/} - {/* Role as Trainer*/} - {/* */} - {/* {*/} - {/* setTestUser({*/} - {/* email: "test2@gmail.com",*/} - {/* password: '123456Abid'*/} - {/* })*/} - {/* }}*/} - {/* size={'small'}*/} - {/* variant="contained"*/} - {/* >*/} - {/* Role as User*/} - {/* */} - {/**/} - + + Forgot password? - - - ); + + + + + + + + + + + + + + ); } \ No newline at end of file