feat: authorize routes added
This commit is contained in:
@@ -22,6 +22,7 @@ import { Navigate } from 'react-router-dom';
|
||||
export interface RouteConfig {
|
||||
path: string;
|
||||
element?: ReactNode;
|
||||
authorize?: boolean;
|
||||
navConfig?: {
|
||||
title: string; // Translation key
|
||||
icon?: Icon;
|
||||
@@ -38,10 +39,12 @@ export const appRoutes: RouteConfig[] = [
|
||||
{
|
||||
path: '/login',
|
||||
element: <AuthenticationPage />,
|
||||
authorize: l,
|
||||
},
|
||||
{
|
||||
path: '/forget-password',
|
||||
element: <ForgetPasswordPage />,
|
||||
authorize: false,
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Suspense, type ReactNode } from 'react';
|
||||
import { createBrowserRouter, type RouteObject } from 'react-router-dom';
|
||||
import { appRoutes, type RouteConfig } from './config';
|
||||
import { ProtectedRoute } from '@/components/ProtectedRoute';
|
||||
|
||||
/**
|
||||
* A recursive function to map our custom route config to the format
|
||||
@@ -18,10 +19,9 @@ function mapRoutes(routes: RouteConfig[]): RouteObject[] {
|
||||
// element = <route.layout>{element}</route.layout>;
|
||||
// }
|
||||
|
||||
// Conditionally wrap the element in the authentication guard
|
||||
// if (route.authRequired) {
|
||||
// element = <ProtectedRoute>{element}</ProtectedRoute>;
|
||||
// }
|
||||
if (route.authorize) {
|
||||
element = <ProtectedRoute>{element}</ProtectedRoute>;
|
||||
}
|
||||
|
||||
return {
|
||||
path: route.path,
|
||||
|
||||
Reference in New Issue
Block a user