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

Fix Email Input Type and Improve Error Messaging on Signup and Login Pages #180

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
13 changes: 13 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"react-dom": "^18",
"react-icons": "^5.2.1",
"react-markdown": "^9.0.1",
"react-toastify": "^10.0.5",
"tailwind-merge": "^2.2.1",
"tailwindcss-animate": "^1.0.7"
},
Expand Down
23 changes: 14 additions & 9 deletions frontend/src/app/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ import Link from "next/link";
import axios from "axios";
import { useRouter } from "next/navigation";
import { useDataContext } from "@/context/dataContext";
import { ToastContainer, toast } from "react-toastify";
import 'react-toastify/dist/ReactToastify.css';

export default function Login() {
const router = useRouter();
const { authState } = useDataContext();

return (
<>
{(authState === "loading" || authState === "notloggedin") && (
<LoginInner />
)}
{authState === "loggedin" && router.push("/")}
</>
);
<ToastContainer />
{(authState === "loading" || authState === "notloggedin") && (
<LoginInner />
)}
{authState === "loggedin" && router.push("/")}
</>
);

}

function LoginInner() {
Expand All @@ -26,13 +30,13 @@ function LoginInner() {
const [loggingIn, setLogginIn] = useState<boolean>(false);
const router = useRouter();
const handleLogin= async (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
e.preventDefault();
// e.preventDefault();
if (email.length == 0) {
setError("*Email can't be empty");
toast.error("Email can't be empty");
return;
}
if (password.length == 0) {
setError("*Password can't be empty");
toast.error("Password can't be empty");
return;
}
//call the api here
Expand Down Expand Up @@ -89,6 +93,7 @@ function LoginInner() {
className="block px-3 w-full rounded-md border-0 py-1.5 text-gray-900 placeholder:text-gray-400 text-sm sm:leading-6"
style={{ outline: 'none' }}
/>

</div>
</div>

Expand Down
13 changes: 8 additions & 5 deletions frontend/src/app/signup/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Link from "next/link";
import axios from "axios";
import { useDataContext } from "@/context/dataContext";
import { useRouter } from "next/navigation";
import { ToastContainer, toast } from "react-toastify";
import 'react-toastify/dist/ReactToastify.css';

export default function Signup() {
const router = useRouter();
Expand All @@ -29,21 +31,21 @@ function SignupInner() {
const [Signingup, setSigningUp] = useState<boolean>(false);

const handleSignup = async (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
e.preventDefault();
// e.preventDefault();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason for this?

if (email.length === 0) {
setError("*Email can't be empty");
toast.error("Email can't be empty");
return;
}
if (username.length === 0) {
setError("* Username can't be empty");
toast.error("Username can't be empty");
return;
}
if (password.length === 0) {
setError("* Password can't be empty");
toast.error("Password can't be empty");
return;
}
if (password !== confirmPassword) {
setError("* Passwords do not match");
toast.error("Passwords do not match");
return;
}

Expand All @@ -67,6 +69,7 @@ function SignupInner() {

return (
<>
<ToastContainer />
<div className="flex min-h-full flex-1 flex-col justify-center px-6 py-12 lg:px-8 homepage">
<div className="text-xs text-red-900 h-2">{error}</div>
<div className="sm:mx-auto sm:w-full sm:max-w-sm">
Expand Down