Skip to content
Snippets Groups Projects
Commit 84ffb0bf authored by Sarthak Shrivastava's avatar Sarthak Shrivastava
Browse files

working login functionality

parent 68f2aca6
No related branches found
No related tags found
No related merge requests found
...@@ -12,7 +12,7 @@ import { useState } from "react"; ...@@ -12,7 +12,7 @@ import { useState } from "react";
import useToken from "./components/useToken"; import useToken from "./components/useToken";
import AccountInformation from "./components/user/AccountInformation"; import AccountInformation from "./components/user/AccountInformation";
import ProtectedRoute from "./routes/ProtectedRoute"; import ProtectedRoute from "./routes/ProtectedRoute";
import PrivateRoutes from "./routes/PrivateRoutes";
function App() { function App() {
// const [token, setToken] = useState(); // const [token, setToken] = useState();
...@@ -29,7 +29,8 @@ function App() { ...@@ -29,7 +29,8 @@ function App() {
<Route path="/" element={<Home />} /> <Route path="/" element={<Home />} />
<Route path="/login" element={<Login setToken={setToken}/>} /> <Route path="/login" element={<Login setToken={setToken}/>} />
<Route path="/register" element={<Register />} /> <Route path="/register" element={<Register />} />
<Route path='/accountinfo' element={<ProtectedRoute token={token}> <AccountInformation token={token}/> </ProtectedRoute>}> <Route element={<PrivateRoutes token={token}/>}>
<Route path='/accountinfo' element={<AccountInformation token={token}/>} />
</Route> </Route>
{/* <Route path="/deleteUser" element={<DeleteUser token={token}/>} /> {/* <Route path="/deleteUser" element={<DeleteUser token={token}/>} />
<Route path="/updatepassword" element={<UpdatePassword />} /> <Route path="/updatepassword" element={<UpdatePassword />} />
......
import { Outlet, Navigate } from 'react-router-dom'
import Axios from "axios";
const PrivateRoutes = ({ token }) => {
let auth = {'token':false}
return(
token ? <Outlet/> : <Navigate to="/login"/>
)
}
export default PrivateRoutes
\ No newline at end of file
...@@ -65,6 +65,9 @@ public class AuthController { ...@@ -65,6 +65,9 @@ public class AuthController {
{ {
Claims claim = JWT.decodeJWT(json.get("jwt")); Claims claim = JWT.decodeJWT(json.get("jwt"));
if (claim != null) if (claim != null)
{
}
res.put("user", claim.getSubject()); res.put("user", claim.getSubject());
} }
else else
......
spring.jpa.hibernate.ddl-auto=none spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/inventory spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/inventory
spring.datasource.username=root spring.datasource.username=root
spring.datasource.password=czarthak spring.datasource.password=CSD@mysql-1872
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#spring.jpa.show-sql: true #spring.jpa.show-sql: true
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment