feat(client): login page
Signed-off-by: Noa Virellia <noa@requiem.garden>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { AxiosError } from 'axios';
|
||||
import axios from 'axios';
|
||||
import { router } from '@/lib/router';
|
||||
|
||||
export const axiosClient = axios.create({
|
||||
baseURL: '/api/',
|
||||
@@ -16,6 +17,7 @@ axiosClient.interceptors.request.use((config) => {
|
||||
axiosClient.interceptors.response.use(undefined, async (error: AxiosError) => {
|
||||
if (error.response && error?.response.status === 401) {
|
||||
// TODO: refresh token
|
||||
await router.navigate({ to: '/login' });
|
||||
if (error.config) {
|
||||
return axiosClient(error.config);
|
||||
}
|
||||
|
||||
13
client/src/lib/router.ts
Normal file
13
client/src/lib/router.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { createRouter } from '@tanstack/react-router';
|
||||
// Import the generated route tree
|
||||
import { routeTree } from '../routeTree.gen';
|
||||
|
||||
// Create a new router instance
|
||||
export const router = createRouter({ routeTree });
|
||||
|
||||
// Register the router instance for type safety
|
||||
declare module '@tanstack/react-router' {
|
||||
interface Register {
|
||||
router: typeof router;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user