diff --git a/team-nishita-dashboard/client/src/App.tsx b/team-nishita-dashboard/client/src/App.tsx
index f5e503357..fb6e61443 100644
--- a/team-nishita-dashboard/client/src/App.tsx
+++ b/team-nishita-dashboard/client/src/App.tsx
@@ -2,7 +2,8 @@ import { useState, useEffect } from 'react';
import { Route, Routes, useNavigate } from 'react-router-dom';
import { jwtDecode } from 'jwt-decode'
import Navbar from './components/Navbar';
-import Home from './components/Home';
+import UserHome from './components/UserHome';
+import AdminHome from './components/AdminHome';
import Signup from './components/Signup';
import Login from './components/Login';
interface User {
@@ -59,7 +60,8 @@ function App() {
- } />
+ } />
+ } />
} />
} />
diff --git a/team-nishita-dashboard/client/src/api/api.tsx b/team-nishita-dashboard/client/src/api/api.tsx
index 358a8856d..5e660f785 100644
--- a/team-nishita-dashboard/client/src/api/api.tsx
+++ b/team-nishita-dashboard/client/src/api/api.tsx
@@ -17,10 +17,17 @@ api.interceptors.request.use((config) => {
return config;
})
-export interface Credentials {
+export interface SignUpCredentials {
+ username: string,
+ password: string,
+ role: string | undefined,
+};
+
+
+export interface LoginCredentials {
username: string,
password: string
};
-export const login = (credentials: Credentials) => api.post('/login', credentials);
-export const signup = (credentials: Credentials) => api.post('/register', credentials);
+export const login = (credentials: LoginCredentials) => api.post('/login', credentials);
+export const signup = (credentials: SignUpCredentials) => api.post('/register', credentials);
export default api;
diff --git a/team-nishita-dashboard/client/src/components/Home.tsx b/team-nishita-dashboard/client/src/components/AdminHome.tsx
similarity index 90%
rename from team-nishita-dashboard/client/src/components/Home.tsx
rename to team-nishita-dashboard/client/src/components/AdminHome.tsx
index 00f29eb65..6cccba37a 100644
--- a/team-nishita-dashboard/client/src/components/Home.tsx
+++ b/team-nishita-dashboard/client/src/components/AdminHome.tsx
@@ -1,7 +1,6 @@
-import { Globe, Lock, ShieldCheck } from 'lucide-react';
import { Link } from 'react-router-dom';
-const Home = () => {
+const AdminHome = () => {
const logged = Boolean(localStorage.getItem('token'));
return (
@@ -33,4 +32,4 @@ const Home = () => {
);
};
-export default Home;
+export default AdminHome;
diff --git a/team-nishita-dashboard/client/src/components/Login.tsx b/team-nishita-dashboard/client/src/components/Login.tsx
index f0c76fcf2..d94039bdf 100644
--- a/team-nishita-dashboard/client/src/components/Login.tsx
+++ b/team-nishita-dashboard/client/src/components/Login.tsx
@@ -1,8 +1,9 @@
import { useState, useEffect } from "react";
import { useNavigate } from 'react-router-dom';
import { login } from '../api/api';
-import type { Credentials as FormData } from '../api/api'
+import type { LoginCredentials as FormData } from '../api/api'
+type UserRole = 'user' | 'admin';
interface LoginProps {
onLogin: (user: { username: string }) => void;
@@ -14,7 +15,7 @@ const Login = ({ onLogin }: LoginProps) => {
const [status, setStatus] = useState("");
const navigate = useNavigate();
- const handleChange = (event: React.ChangeEvent) => {
+ const handleChange = (event: React.ChangeEvent) => {
setFormData({ ...formData, [event.target.name]: event.target.value });
};
@@ -24,7 +25,12 @@ const Login = ({ onLogin }: LoginProps) => {
const response = await login(formData);
localStorage.setItem('token', response.data.access_token);
onLogin({ username: formData.username });
- navigate('/home');
+ const role: UserRole = response.data.role;
+ if (role === 'user') {
+ navigate('/userHome')
+ } else {
+ navigate('/adminHome')
+ }
} catch (error) {
console.error(error);
setStatus("Login failed. Please check your credentials.");
diff --git a/team-nishita-dashboard/client/src/components/Signup.tsx b/team-nishita-dashboard/client/src/components/Signup.tsx
index 053c64e78..0635cb6a6 100644
--- a/team-nishita-dashboard/client/src/components/Signup.tsx
+++ b/team-nishita-dashboard/client/src/components/Signup.tsx
@@ -1,20 +1,20 @@
import { useState, useEffect } from "react";
import { useNavigate } from 'react-router-dom';
import { signup } from '../api/api';
-import type { Credentials as FormData } from '../api/api'
+import type { SignUpCredentials as FormData } from '../api/api'
interface SignupProps {
- onLogin: (user: { username: string }) => void;
+ onLogin: (user: { username: string, role: string }) => void;
}
const Signup = ({ onLogin }: SignupProps) => {
- const [formData, setFormData] = useState({ username: "", password: "" });
+ const [formData, setFormData] = useState({ username: "", password: "", role: "" });
const [showPassword, setShowPassword] = useState(false);
const [status, setStatus] = useState("");
const navigate = useNavigate();
- const handleChange = (event: React.ChangeEvent) => {
+ const handleChange = (event: React.ChangeEvent) => {
setFormData({ ...formData, [event.target.name]: event.target.value });
};
@@ -23,7 +23,10 @@ const Signup = ({ onLogin }: SignupProps) => {
try {
const response = await signup(formData);
localStorage.setItem('token', response.data.access_token);
- onLogin({ username: formData.username });
+ if (formData.role === undefined) {
+ throw new Error('Provide User Role');
+ }
+ onLogin({ username: formData.username, role: formData.role });
navigate('/home');
} catch (error) {
console.error(error);
@@ -84,6 +87,23 @@ const Signup = ({ onLogin }: SignupProps) => {
{showPassword ? 'Hide' : 'Show'}
+
+
+
+