Created component for authorized route
This commit is contained in:
		
							parent
							
								
									fe89ae0970
								
							
						
					
					
						commit
						cc9678f375
					
				
					 1 changed files with 18 additions and 0 deletions
				
			
		
							
								
								
									
										18
									
								
								frontend/src/Components/AuthorizedRoute.tsx
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								frontend/src/Components/AuthorizedRoute.tsx
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,18 @@ | |||
| import { Navigate } from "react-router-dom"; | ||||
| import React from "react"; | ||||
| 
 | ||||
| interface AuthorizedRouteProps { | ||||
|   children: React.ReactNode; | ||||
|   isAuthorized: boolean; | ||||
| } | ||||
| 
 | ||||
| export function AuthorizedRoute({ | ||||
|   children, | ||||
|   isAuthorized, | ||||
| }: AuthorizedRouteProps): JSX.Element { | ||||
|   if (!isAuthorized) { | ||||
|     return <Navigate to="/unauthorized" />; | ||||
|   } | ||||
| 
 | ||||
|   return children as React.ReactElement; | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Mattias
						Mattias