From 7dfbe0f363a434cfda5f9be996d194f03c36879c Mon Sep 17 00:00:00 2001 From: Biswakalyan Bhuyan Date: Wed, 31 Jul 2024 12:16:49 +0530 Subject: new project --- panel/src/pages/LoginPage.jsx | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 panel/src/pages/LoginPage.jsx (limited to 'panel/src/pages/LoginPage.jsx') diff --git a/panel/src/pages/LoginPage.jsx b/panel/src/pages/LoginPage.jsx new file mode 100644 index 0000000..37ce32f --- /dev/null +++ b/panel/src/pages/LoginPage.jsx @@ -0,0 +1,52 @@ +import React, { useState } from 'react'; +import { signInWithEmailAndPassword } from 'firebase/auth'; +import { auth } from '../firebase'; + +const LoginPage = () => { + const [email, setEmail] = useState(''); + const [password, setPassword] = useState(''); + const [error, setError] = useState(''); + + const handleLogin = async () => { + if (password.length < 8) { + setError('The password should be minimum 8 digits'); + return; + } + + try { + await signInWithEmailAndPassword(auth, email, password); + } catch (error) { + setError(error.message); + } + }; + + return ( +
+
+

Login

+
+ + setEmail(e.target.value)} + className="form-control" + /> +
+
+ + setPassword(e.target.value)} + className="form-control" + /> +
+ {error &&

{error}

} + +
+
+ ); +}; + +export default LoginPage; -- cgit v1.2.3-59-g8ed1b From 1bc31e4d8c8d23230bdac1b2bd73e76c8d455222 Mon Sep 17 00:00:00 2001 From: Biswakalyan Bhuyan Date: Wed, 31 Jul 2024 12:37:38 +0530 Subject: update --- panel/src/components/PrivateRoute.jsx | 23 +++++++++++++++-------- panel/src/pages/LoginPage.jsx | 10 ++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) (limited to 'panel/src/pages/LoginPage.jsx') diff --git a/panel/src/components/PrivateRoute.jsx b/panel/src/components/PrivateRoute.jsx index 04e00f7..2160f74 100644 --- a/panel/src/components/PrivateRoute.jsx +++ b/panel/src/components/PrivateRoute.jsx @@ -1,10 +1,17 @@ -import React from 'react'; -import { Navigate, Outlet } from 'react-router-dom'; -import { useAuth } from '../contexts/AuthContext'; +import { BrowserRouter as Router, Route, Routes } from 'react-router-dom'; +import LoginPage from '../pages/LoginPage'; +import Dashboard from '../pages/Dashboard'; // Assuming you have a Dashboard component -const PrivateRoute = () => { - const { currentUser } = useAuth(); - return currentUser ? : ; -}; +function App() { + return ( + + + } /> + } /> + {/* Other routes */} + + + ); +} -export default PrivateRoute; +export default App; diff --git a/panel/src/pages/LoginPage.jsx b/panel/src/pages/LoginPage.jsx index 37ce32f..f763325 100644 --- a/panel/src/pages/LoginPage.jsx +++ b/panel/src/pages/LoginPage.jsx @@ -1,4 +1,5 @@ import React, { useState } from 'react'; +import { useNavigate } from 'react-router-dom'; // Import useNavigate import { signInWithEmailAndPassword } from 'firebase/auth'; import { auth } from '../firebase'; @@ -6,17 +7,26 @@ const LoginPage = () => { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); + const navigate = useNavigate(); // Get the navigation function const handleLogin = async () => { + console.log('Attempting login...'); + console.log('Email:', email); + console.log('Password:', password); + if (password.length < 8) { setError('The password should be minimum 8 digits'); + console.log('Error:', 'The password should be minimum 8 digits'); return; } try { await signInWithEmailAndPassword(auth, email, password); + console.log('Login successful'); + navigate('/dashboard'); // Redirect to the dashboard after successful login } catch (error) { setError(error.message); + console.log('Error:', error.message); } }; -- cgit v1.2.3-59-g8ed1b