Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added password hide/show toggle #187

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added public/eye-hide.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/eye.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions src/app/auth/page.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,22 @@
cursor: pointer;
color: var(--slate-black);
}

.passwordContainer{
position: relative;

}

.passwordToggle{
position: absolute;
height: 100%;
display: flex;
top: 0;
align-items: center;
right: 1rem
}

.image{
height: 25px;
width: 25px;
}
79 changes: 56 additions & 23 deletions src/app/auth/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ import { toast } from "sonner";
import { loginSchema, signupSchema } from "@/lib/zod";
import { signIn } from "next-auth/react";
import { useRouter, useSearchParams } from "next/navigation";
import eye from "../../../public/eye.png"
import hide from "../../../public/eye-hide.png"
import Image from 'next/image';

export default function Auth() {
const [isSignup, setIsSignup] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const [hidden, setHidden] = useState(true);
const [confirmHidden, setConfirmHidden] = useState(true);
const router = useRouter();
const searchParams = useSearchParams();
const callback = searchParams.get("callbackUrl");
Expand Down Expand Up @@ -161,27 +166,46 @@ export default function Auth() {
{errors.email.message?.toString()}
</p>
)}

<input
type="password"
placeholder="Password"
disabled={isLoading}
{...register("password")}
className={styles.input}
/>
<div className={styles.passwordContainer} >
<input
type={hidden ? "password" : "text"}
placeholder="Password"
disabled={isLoading}
{...register("password")}
className={styles.input}
/>
<button className={styles.passwordToggle} onClick={(e)=>{
e.preventDefault()
setHidden(!hidden)
}}>
{
hidden ? <Image className={styles.image} src={hide} alt="My Image" /> : <Image className={styles.image} src={eye} alt="My Image" />
}
</button>
</div>
{errors.password && (
<p className={styles.errors}>
{errors.password.message?.toString()}
</p>
)}

<input
type="password"
placeholder="Confirm Password"
{...register("confirmPassword")}
className={styles.input}
disabled={isLoading}
/>
<div className={styles.passwordContainer} >
<input
type={confirmHidden ? "password" : "text"}
placeholder="Confirm Password"
{...register("confirmPassword")}
className={styles.input}
disabled={isLoading}
/>
<button className={styles.passwordToggle} onClick={(e)=>{
e.preventDefault()
setConfirmHidden(!confirmHidden)
}}>
{
confirmHidden ? <Image className={styles.image} src={hide} alt="My Image" /> : <Image className={styles.image} src={eye} alt="My Image" />
}
</button>
</div>
{errors.confirmPassword && (
<p className={styles.errors}>
{errors.confirmPassword.message?.toString()}
Expand Down Expand Up @@ -214,14 +238,23 @@ export default function Auth() {
{errors.loginIdentifier.message?.toString()}
</p>
)}

<input
type="password"
placeholder="Password"
{...register("password")}
className={styles.input}
disabled={isLoading}
/>
<div className={styles.passwordContainer} >
<input
type={hidden? "password" : "text"}
placeholder="Password"
{...register("password")}
className={styles.input}
disabled={isLoading}
/>
<button className={styles.passwordToggle} onClick={(e)=>{
e.preventDefault()
setHidden(!hidden)
}}>
{
hidden ? <Image className={styles.image} src={hide} alt="My Image" /> : <Image className={styles.image} src={eye} alt="My Image" />
}
</button>
</div>
{errors.password && (
<p className={styles.errors}>
{errors.password.message?.toString()}
Expand Down
Loading