Added logout feature
This commit is contained in:
parent
a3480aec17
commit
f872fb20f6
|
|
@ -14,6 +14,7 @@ import { createFileRoute } from '@tanstack/react-router'
|
|||
|
||||
import { Route as rootRoute } from './routes/__root'
|
||||
import { Route as DashboardLayoutImport } from './routes/_dashboardLayout'
|
||||
import { Route as LogoutIndexImport } from './routes/logout/index'
|
||||
import { Route as LoginIndexImport } from './routes/login/index'
|
||||
import { Route as DashboardLayoutDashboardIndexImport } from './routes/_dashboardLayout/dashboard/index'
|
||||
|
||||
|
|
@ -36,6 +37,11 @@ const IndexLazyRoute = IndexLazyImport.update({
|
|||
getParentRoute: () => rootRoute,
|
||||
} as any).lazy(() => import('./routes/index.lazy').then((d) => d.Route))
|
||||
|
||||
const LogoutIndexRoute = LogoutIndexImport.update({
|
||||
path: '/logout/',
|
||||
getParentRoute: () => rootRoute,
|
||||
} as any)
|
||||
|
||||
const LoginIndexRoute = LoginIndexImport.update({
|
||||
path: '/login/',
|
||||
getParentRoute: () => rootRoute,
|
||||
|
|
@ -71,6 +77,10 @@ declare module '@tanstack/react-router' {
|
|||
preLoaderRoute: typeof LoginIndexImport
|
||||
parentRoute: typeof rootRoute
|
||||
}
|
||||
'/logout/': {
|
||||
preLoaderRoute: typeof LogoutIndexImport
|
||||
parentRoute: typeof rootRoute
|
||||
}
|
||||
'/_dashboardLayout/dashboard/': {
|
||||
preLoaderRoute: typeof DashboardLayoutDashboardIndexImport
|
||||
parentRoute: typeof DashboardLayoutImport
|
||||
|
|
@ -91,6 +101,7 @@ export const routeTree = rootRoute.addChildren([
|
|||
DashboardLayoutUsersIndexLazyRoute,
|
||||
]),
|
||||
LoginIndexRoute,
|
||||
LogoutIndexRoute,
|
||||
])
|
||||
|
||||
/* prettier-ignore-end */
|
||||
|
|
|
|||
24
apps/frontend/src/routes/logout/index.tsx
Normal file
24
apps/frontend/src/routes/logout/index.tsx
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import isAuthenticated from "@/utils/isAuthenticated";
|
||||
import { createFileRoute, useNavigate } from "@tanstack/react-router";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export const Route = createFileRoute("/logout/")({
|
||||
component: LogoutPage,
|
||||
});
|
||||
|
||||
export default function LogoutPage() {
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
if (isAuthenticated()) {
|
||||
localStorage.removeItem("accessToken");
|
||||
}
|
||||
|
||||
navigate({
|
||||
to: "/login",
|
||||
replace: true,
|
||||
});
|
||||
}, [navigate]);
|
||||
|
||||
return <div>Logging out...</div>;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user