Skip to content

Commit

Permalink
bug fix | update
Browse files Browse the repository at this point in the history
  • Loading branch information
TajwarSaiyeed committed Sep 1, 2023
1 parent fe94f63 commit 2e8effb
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 136 deletions.
193 changes: 127 additions & 66 deletions app/(auth)/signin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,32 @@
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 {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 {Avatar, Button, CssBaseline, TextField, Box, Typography,Container} from '@mui/material/';
import {createTheme, ThemeProvider} from '@mui/material/styles';
import {FieldValues, SubmitHandler, useForm} from "react-hook-form";
import {Avatar, Button, CssBaseline, TextField, Box, Typography, Container} from '@mui/material/';

const defaultTheme = createTheme();

export default function SignInPage() {
const [isSubmitting, setIsSubmitting] = useState<boolean>(false);
const { status } = useSession();

const [testUser, setTestUser] = useState<{
email: string,
password: string
}>({
email: "",
password: ""
})

const {status} = useSession();

const {
register,
handleSubmit,
formState: { errors },
formState: {errors},
} = useForm<FieldValues>({
defaultValues: {
email: "",
Expand Down Expand Up @@ -48,7 +57,7 @@ export default function SignInPage() {
};

if (status === "loading") {
return <Loader />;
return <Loader/>;
}

if (status === "authenticated") {
Expand All @@ -57,70 +66,122 @@ export default function SignInPage() {

return (
<ThemeProvider theme={defaultTheme}>
<Container component="main" maxWidth="xs">
<CssBaseline />
<Box
sx={{
marginTop: 8,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
}}
>
<Avatar sx={{ m: 1, backgroundColor: 'secondary.main' }}>
<LockOutlinedIcon />
</Avatar>
<Typography component="h1" variant="h5">
Sign in
</Typography>
<Box component="form" noValidate onSubmit={handleSubmit(handleSignIn)} sx={{ mt: 1 }}>
<TextField
margin="normal"
required
fullWidth
id="email"
label="Email Address"
autoComplete="email"
autoFocus
{...register("email", {
required: "This field is required",
})}
error={!!errors?.email?.message}
helperText={
errors.email && typeof errors.email.message === "string"
? errors.email.message
: null
}
/>
<Container component="main" maxWidth="sm">
<CssBaseline/>
<Box
sx={{
marginTop: 8,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
}}
>
<Avatar sx={{m: 1, backgroundColor: 'secondary.main'}}>
<LockOutlinedIcon/>
</Avatar>
<Typography component="h1" variant="h5">
Sign in
</Typography>
<Box component="form" noValidate onSubmit={handleSubmit(handleSignIn)} sx={{mt: 1}}>
<TextField
margin="normal"
value={testUser.email}
required
fullWidth
id="email"
label="Email Address"
autoComplete="email"
autoFocus
{...register("email", {
required: "This field is required",
})}
error={!!errors?.email?.message}
helperText={
errors?.email && typeof errors?.email?.message === "string"
? errors?.email?.message
: null
}
/>

<TextField
margin="normal"
value={testUser.password}
required
fullWidth
label="Password"
type="password"
id="password"
autoComplete="current-password"
{...register("password", {
required: "This field is required",
})}
error={!!errors?.password?.message}
helperText={
errors?.password && typeof errors?.password?.message === "string"
? errors?.password?.message
: null
}
/>

<TextField
margin="normal"
required
fullWidth
label="Password"
type="password"
id="password"
autoComplete="current-password"
{...register("password", { required: "This field is required" })}
error={!!errors?.password?.message}
helperText={
errors.password && typeof errors.password.message === "string"
? errors.password.message
: null
}
/>
<Button
type="submit"
fullWidth
variant="contained"
sx={{mt: 3, mb: 2}}
>
{isSubmitting ? "Signing in..." : "Sign in"}
</Button>
</Box>
</Box>

<Box sx={{
display: "flex",
justifyContent: "center",
alignItems: "center",
gap: 1,
flexDirection: {
xs: "column",
sm: "row"
}
}}>
<Button
onClick={() => {
setTestUser({
email: "rjabid36@gmail.com",
password: '123456Abid'
})
}}
size={'small'}
variant="contained"
>
Role as Admin
</Button>
<Button
onClick={() => {
setTestUser({
email: "test1@gmail.com",
password: '123456Abid'
})
}}
size={'small'}
variant="contained"
>
Role as Trainer
</Button>
<Button
type="submit"
fullWidth
onClick={() => {
setTestUser({
email: "test2@gmail.com",
password: '123456Abid'
})
}}
size={'small'}
variant="contained"
sx={{ mt: 3, mb: 2 }}
>
{isSubmitting ? "Signing in..." : "Sign in"}
Role as User
</Button>
</Box>
</Box>
</Container>
</ThemeProvider>
</Container>
</ThemeProvider>
);
}
Loading

0 comments on commit 2e8effb

Please sign in to comment.