-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integrated login and register functionalities (#15)
- Loading branch information
Showing
11 changed files
with
796 additions
and
504 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,47 @@ | ||
import { Footer, Navbar } from './components/layout' | ||
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom'; | ||
import Home from './pages/Home' | ||
import Login from './pages/auth/Login'; | ||
import Register from './pages/auth/Register'; | ||
import Auth from './pages/auth/Auth'; | ||
import { ForgotPassword, ResetPassword } from './pages/auth/forgot-password'; | ||
import About from './pages/About'; | ||
|
||
|
||
import { Footer, Navbar } from "./components/layout"; | ||
import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; | ||
import Home from "./pages/Home"; | ||
import Login from "./pages/auth/Login"; | ||
import Register from "./pages/auth/Register"; | ||
import Auth from "./pages/auth/Auth"; | ||
import { ForgotPassword, ResetPassword } from "./pages/auth/forgot-password"; | ||
import About from "./pages/About"; | ||
|
||
import { Toaster } from "react-hot-toast"; | ||
|
||
const App = () => { | ||
|
||
|
||
|
||
return ( | ||
<Router> | ||
<div className='relative h-full max-w-[4000px] '> | ||
<div className='fixed top-0 z-30 w-full overflow-hidden'> | ||
<Navbar /> | ||
</div> | ||
<Routes> | ||
<Route path='/auth' element={<Auth />}> | ||
<Route path='login' element={<Login />} /> | ||
<Route path='register' element={<Register />} /> | ||
</Route> | ||
<Route path='/auth/forgot-password' element={<ForgotPassword />} /> | ||
<Route path='/auth/reset-password' element={<ResetPassword />} /> | ||
<Route path='/' element={<Home />} /> | ||
<Route path='/about' element={<About />} /> | ||
</Routes> | ||
|
||
<div className='bg-transparent'> | ||
<Footer /> | ||
</div> | ||
</div> | ||
</Router> | ||
); | ||
} | ||
|
||
export default App; | ||
return ( | ||
<> | ||
<Router> | ||
<div className="relative h-full max-w-[4000px] "> | ||
<div className="fixed top-0 z-30 w-full overflow-hidden"> | ||
<Navbar /> | ||
</div> | ||
<Routes> | ||
<Route path="/auth" element={<Auth />}> | ||
<Route path="login" element={<Login />} /> | ||
<Route path="register" element={<Register />} /> | ||
</Route> | ||
<Route | ||
path="/auth/forgot-password" | ||
element={<ForgotPassword />} | ||
/> | ||
<Route | ||
path="/auth/reset-password" | ||
element={<ResetPassword />} | ||
/> | ||
<Route path="/" element={<Home />} /> | ||
<Route path="/about" element={<About />} /> | ||
</Routes> | ||
|
||
<div className="bg-transparent"> | ||
<Footer /> | ||
</div> | ||
</div> | ||
</Router> | ||
<Toaster position="top-right" /> | ||
</> | ||
); | ||
}; | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,43 @@ | ||
import axios, { AxiosError, InternalAxiosRequestConfig } from "axios"; | ||
import axios, { | ||
AxiosError, | ||
AxiosResponse, | ||
InternalAxiosRequestConfig, | ||
} from "axios"; | ||
|
||
const baseURL = `${import.meta.env.VITE_PUBLIC_API_URL}/api/v1/`; | ||
|
||
// Create an axios instance with the base URL | ||
const axiosClient = axios.create({ | ||
baseURL, | ||
baseURL, | ||
}); | ||
|
||
axiosClient.interceptors.request.use( | ||
(config: InternalAxiosRequestConfig) => { | ||
// config.headers["access-control-allow-origin"] = "*"; | ||
return config; | ||
}, | ||
(error: AxiosError) => { | ||
return Promise.reject(error); | ||
} | ||
(config: InternalAxiosRequestConfig) => { | ||
const resource = localStorage.getItem("TOKEN"); | ||
if (resource) { | ||
const token = JSON.parse(resource).access_token; | ||
config.headers.Authorization = `Bearer ${token}`; | ||
} | ||
// config.headers["access-control-allow-origin"] = "*"; | ||
return config; | ||
}, | ||
(error: AxiosError) => { | ||
return Promise.reject(error); | ||
} | ||
); | ||
|
||
export default axiosClient; | ||
// Response interceptor to handle errors | ||
axiosClient.interceptors.response.use( | ||
(response: AxiosResponse) => { | ||
return response; | ||
}, | ||
(error: AxiosError) => { | ||
if (error.response && error.response.status === 401) { | ||
localStorage.removeItem("TOKEN"); | ||
window.location.reload(); | ||
} | ||
return Promise.reject(error); | ||
} | ||
); | ||
|
||
export default axiosClient; |
Oops, something went wrong.