aboutsummaryrefslogtreecommitdiffstats
path: root/src/components
diff options
context:
space:
mode:
authorLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-07-25 13:13:05 +0530
committerLibravatarLibravatar Biswakalyan Bhuyan <biswa@surgot.in> 2024-07-25 13:13:05 +0530
commite0ab73361a8bb3598ced59270e6824aa80b80b48 (patch)
treef25eb530a760b73faac631693a7e08539473d3ed /src/components
parent57ac476e3303993ea523c43b7de638d4f1ce3e85 (diff)
downloadadmin-panel-e0ab73361a8bb3598ced59270e6824aa80b80b48.tar.gz
admin-panel-e0ab73361a8bb3598ced59270e6824aa80b80b48.tar.bz2
admin-panel-e0ab73361a8bb3598ced59270e6824aa80b80b48.zip
added admin page
Diffstat (limited to 'src/components')
-rw-r--r--src/components/Admin.js35
-rw-r--r--src/components/Login.js4
-rw-r--r--src/components/MyComponent.js7
3 files changed, 38 insertions, 8 deletions
diff --git a/src/components/Admin.js b/src/components/Admin.js
new file mode 100644
index 0000000..aeb8bf6
--- /dev/null
+++ b/src/components/Admin.js
@@ -0,0 +1,35 @@
+import React, { useEffect, useState } from 'react';
+import axios from 'axios';
+
+function Admin() {
+ const [message, setMessage] = useState('');
+
+ useEffect(() => {
+ const fetchData = async () => {
+ const token = localStorage.getItem('jwtToken');
+ if (token) {
+ try {
+ const response = await axios.get('http://localhost:5000/admin', {
+ headers: { Authorization: `Bearer ${token}` },
+ });
+ setMessage(response.data.message);
+ } catch (error) {
+ console.error('Error fetching admin data', error);
+ }
+ } else {
+ setMessage('You are not authorized to view this page.');
+ }
+ };
+
+ fetchData();
+ }, []);
+
+ return (
+ <div className="Admin">
+ <h2>Admin Panel</h2>
+ <p>{message}</p>
+ </div>
+ );
+}
+
+export default Admin;
diff --git a/src/components/Login.js b/src/components/Login.js
index c73b59a..717a3ae 100644
--- a/src/components/Login.js
+++ b/src/components/Login.js
@@ -1,10 +1,12 @@
import React, { useState } from 'react';
import axios from 'axios';
+import { useNavigate } from 'react-router-dom';
function Login() {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
+ const navigate = useNavigate(); // Initialize useNavigate hook
const handleSubmit = async (event) => {
event.preventDefault();
@@ -17,7 +19,7 @@ function Login() {
const { token } = response.data;
console.log('Login successful, token:', token);
localStorage.setItem('jwtToken', token);
- // Redirect to admin panel or another page after successful login
+ navigate('/admin'); // Redirect to the admin page
} catch (error) {
setError('Invalid credentials');
console.error('Error logging in', error);
diff --git a/src/components/MyComponent.js b/src/components/MyComponent.js
deleted file mode 100644
index b9434ea..0000000
--- a/src/components/MyComponent.js
+++ /dev/null
@@ -1,7 +0,0 @@
-import React from 'react';
-
-function MyComponent() {
- return <div>This is my component!</div>;
-}
-
-export default MyComponent; \ No newline at end of file