Skip to content

Commit

Permalink
Merge pull request #252 from harshbhar0629/BUG/Input-Validations
Browse files Browse the repository at this point in the history
Bug: Input validations in forms
  • Loading branch information
skmirajulislam authored Oct 13, 2024
2 parents 33dde23 + 924f6a7 commit d94fd90
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"react-bootstrap": "^2.10.5",
"react-dom": "^18.3.1",
"react-firebase-hooks": "^5.1.1",
"react-hot-toast": "^2.4.1",
"react-icon": "^1.0.0",
"react-icons": "^5.3.0",
"react-native-linear-gradient": "^2.8.3",
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/components/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import React, { useState, useEffect } from "react";
import { useNavigate, Link } from "react-router-dom";
import { useSignInWithEmailAndPassword } from "react-firebase-hooks/auth";
import { auth } from "../Firebase/firebase";
import toast from "react-hot-toast";
import Footer from "../Footer/Footer";


// LoginHeader Component
const LoginHeader = () => (
<h2 className="text-center mb-4">Login</h2>
Expand Down Expand Up @@ -66,6 +68,7 @@ const LoginFooter = ({ navigate }) => (
);

function Login() {
const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [showPassword, setShowPassword] = useState(false);
Expand All @@ -74,6 +77,10 @@ function Login() {

const handleLogin = async (e) => {
e.preventDefault();
if (!regex.test(email)) {
toast.error("Invalid Email");
return;
}
await signInWithEmailAndPassword(email, password);
};

Expand Down
8 changes: 8 additions & 0 deletions frontend/src/components/Signup/Signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import { useNavigate } from "react-router-dom";
import { useCreateUserWithEmailAndPassword } from "react-firebase-hooks/auth";
import { auth } from "../Firebase/firebase"; // Import Firebase auth
import { registerValidation } from "../../validations/validation";
import toast from "react-hot-toast";
import Footer from "../Footer/Footer.js";


function Signup() {
const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [confirmPassword, setConfirmPassword] = useState("");
Expand Down Expand Up @@ -40,6 +43,11 @@ function Signup() {
const handleSignup = async (e) => {
e.preventDefault();

if (!regex.test(email)) {
toast.error("Invalid email");
return;
}

try {
await registerValidation.validate(
{ email, password, confirmPassword },
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import ReactDOM from 'react-dom';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { BrowserRouter } from 'react-router-dom';
import { Toaster } from "react-hot-toast";


const root = document.getElementById('root');
ReactDOM.render(
<React.StrictMode>
<BrowserRouter>
<App />
<Toaster />
</BrowserRouter>
</React.StrictMode>,
root
Expand Down

0 comments on commit d94fd90

Please sign in to comment.