Skip to content

Commit

Permalink
Merge pull request #395 from saras-69/pass-recov
Browse files Browse the repository at this point in the history
Password-Recovery-Feature
  • Loading branch information
dhairyagothi authored Oct 23, 2024
2 parents 33993cf + 7f5346e commit d6a48ef
Show file tree
Hide file tree
Showing 5 changed files with 320 additions and 223 deletions.
17 changes: 2 additions & 15 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"framer-motion": "^11.11.8",
"google-translate-api-x": "^10.7.1",
"jwt-decode": "^4.0.0",
"leaflet": "^1.9.4",
"react": "^18.3.1",
"react-datepicker": "^7.4.0",
"react-dom": "^18.3.1",
Expand Down
137 changes: 67 additions & 70 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,102 +1,99 @@
import React, { useEffect } from 'react'
import Herosection from './Pages/Herosection'
import LoginPage from './Pages/LoginPage';
import Register from './Pages/Register';
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import chatbotsvg from './assets/svg/chatbot.svg';
import { useNavigate, Outlet } from 'react-router-dom';
import RailwayStations from './Pages/stations';
import NavigationPage from './Pages/navigation';
import './App.css'
import BookingPage from './Pages/booking';
import MapPage from './Pages/3Dmaps';
import SchedulePage from './Pages/schedule';
import NotificationPage from './Pages/notification';
import Chatbot from './components/chatbot';
import ContactUs from './Pages/ContactUs';
import Settings from './components/Settings';
import Help from './components/help';
import About from './components/about';
import Contributor from './Pages/contributor';
import Payment from './Pages/Payment';
import HelpAndSupport from './Pages/HelpandSupport';
import Emergency from './Pages/Emergency';
import AboutUs from './Pages/AboutUs';
import Error from './Pages/Error';
import User from './Pages/User';
import React, { useEffect } from "react";
import Herosection from "./Pages/Herosection";
import LoginPage from "./Pages/LoginPage";
import Register from "./Pages/Register";
import PasswordRecovery from "./Pages/PasswordRecovery";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import chatbotsvg from "./assets/svg/chatbot.svg";
import { useNavigate, Outlet } from "react-router-dom";
import RailwayStations from "./Pages/stations";
import NavigationPage from "./Pages/navigation";
import "./App.css";
import BookingPage from "./Pages/booking";
import MapPage from "./Pages/3Dmaps";
import SchedulePage from "./Pages/schedule";
import NotificationPage from "./Pages/notification";
import Chatbot from "./components/chatbot";
import ContactUs from "./Pages/ContactUs";
import Settings from "./components/Settings";
import Help from "./components/help";
import About from "./components/about";
import Contributor from "./Pages/contributor";
import Payment from "./Pages/Payment";
import HelpAndSupport from "./Pages/HelpandSupport";
import Emergency from "./Pages/Emergency";
import AboutUs from "./Pages/AboutUs";
import Error from "./Pages/Error";
import User from "./Pages/User";

function App() {

return (
<>
<Router>
<Routes>
<Route path="/" element={<Herosection />} />
<Route path="/Login" element={<LoginPage />} />
<Route path="/Register" element={<Register />} />
<Route path='/Stations' element={<RailwayStations/>} />
<Route path='/Navigation' element={<NavigationPage/>} />
<Route path='/Booking' element={<BookingPage/>} />
<Route path='/3DMap' element={<MapPage/>} />
<Route path='/Schedule' element={<SchedulePage/>} />
<Route path='/Notification' element={<NotificationPage/>} />
<Route path='/chatbot' element={<Chatbot/>} />
<Route path='/ContactUs' element={<ContactUs/>} />
<Route path='/Settings' element={<Settings/>} />
<Route path='/help' element={<Help/>} />
<Route path='/about' element={<About/>} />
<Route path='/contributor' element={<Contributor/>} />
<Route path='/payment' element={<Payment/>} />
<Route path='/aboutus' element={<AboutUs/>} />
<Route path='/emergency' element={<Emergency/>} />
<Route path='/help-and-support' element={<HelpAndSupport/>} />
<Route path='/help-and-support' element={<HelpAndSupport/>} />
<Route path='*' element={<Error/>} />
<Route path='/user' element={<User/>} />
{/* This route is just for testing protected routes it can be removed later when there is a route other than login or signup */}

</Routes>
</Router>
<Router>
<Routes>
<Route path='/' element={<Herosection />} />
<Route path='/Login' element={<LoginPage />} />
<Route path='/Register' element={<Register />} />
<Route path='/password-recovery' element={<PasswordRecovery />} />
<Route path='/Stations' element={<RailwayStations />} />
<Route path='/Navigation' element={<NavigationPage />} />
<Route path='/Booking' element={<BookingPage />} />
<Route path='/3DMap' element={<MapPage />} />
<Route path='/Schedule' element={<SchedulePage />} />
<Route path='/Notification' element={<NotificationPage />} />
<Route path='/chatbot' element={<Chatbot />} />
<Route path='/ContactUs' element={<ContactUs />} />
<Route path='/Settings' element={<Settings />} />
<Route path='/help' element={<Help />} />
<Route path='/about' element={<About />} />
<Route path='/contributor' element={<Contributor />} />
<Route path='/payment' element={<Payment />} />
<Route path='/aboutus' element={<AboutUs />} />
<Route path='/emergency' element={<Emergency />} />
<Route path='/help-and-support' element={<HelpAndSupport />} />
<Route path='/help-and-support' element={<HelpAndSupport />} />
<Route path='*' element={<Error />} />
<Route path='/user' element={<User />} />
{/* This route is just for testing protected routes it can be removed later when there is a route other than login or signup */}
</Routes>
</Router>

{/* <div className='fixed bottom-0 right-0 z-50 m-4 cursor-pointer'>
{/* <div className='fixed bottom-0 right-0 z-50 m-4 cursor-pointer'>
<img src={chatbotsvg} alt="chatbot" className='w-16 h-16' />
</div> */}

</>
)
</>
);
}

export default App;



export function ProtectedRoute() {
const navigate = useNavigate();

// Async function to verify the token
const verifyToken = async () => {
try {
const res = await fetch('http://localhost:3000/auth/verify', {
method: 'GET',
const res = await fetch("http://localhost:3000/auth/verify", {
method: "GET",
headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
},
credentials: 'include'
credentials: "include",
});

const data = await res.json();
console.log('Token Verification error:', data.error); // For debugging
console.log("Token Verification error:", data.error); // For debugging

if (data.error || res.status === 400 || res.status === 500) {
navigate('/Login');
navigate("/Login");
}

if (res.status === 400 || res.status === 500) {
navigate('/Login');
navigate("/Login");
}
} catch (error) {
console.error('Error verifying token:', error);
navigate('/Login');
console.error("Error verifying token:", error);
navigate("/Login");
}
};

Expand Down
Loading

0 comments on commit d6a48ef

Please sign in to comment.