mirror of
https://github.com/rjNemo/ticket_manager
synced 2026-06-06 00:36:39 +00:00
PrivateRoute and API protected
This commit is contained in:
parent
7115d28044
commit
f23bfad793
5 changed files with 7 additions and 8 deletions
|
|
@ -13,7 +13,7 @@ using TicketManager.Resources;
|
|||
|
||||
namespace TicketManager.Controllers
|
||||
{
|
||||
// [Authorize]
|
||||
[Authorize]
|
||||
[Produces("application/json")]
|
||||
[Route("api/v1/users")]
|
||||
[ApiController]
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ using System;
|
|||
namespace TicketManager.Controllers
|
||||
{
|
||||
// [Authorize(Roles = "Admin")]
|
||||
// [Authorize]
|
||||
[Authorize]
|
||||
[Produces("application/json")]
|
||||
[Route("api/v1/[controller]")]
|
||||
[ApiController]
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ using TicketManager.Models;
|
|||
|
||||
namespace TicketManager.Controllers
|
||||
{
|
||||
// [Authorize]
|
||||
[Authorize]
|
||||
[Route("api/v1/[controller]")]
|
||||
[ApiController]
|
||||
public class TicketsController : ControllerBase
|
||||
|
|
|
|||
|
|
@ -6,13 +6,12 @@ import { UserController } from "../controllers/UserController";
|
|||
import { TicketController } from "../controllers/TicketController";
|
||||
import { NotFoundPage } from "../pages/NotFoundPage";
|
||||
import { TestPage } from "../pages/TestPage";
|
||||
import { PrivateRoute } from "./PrivateRoute";
|
||||
|
||||
export const AppRouter = () => {
|
||||
return (
|
||||
<Switch>
|
||||
<Route exact path="/test">
|
||||
<TestPage />
|
||||
</Route>
|
||||
<PrivateRoute path="/test" component={TestPage} />
|
||||
|
||||
<Route exact path="/">
|
||||
<HomeController />
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@ export const PrivateRoute = ({ component: Component, path, ...rest }) => {
|
|||
}
|
||||
const fn = async () => {
|
||||
await loginWithRedirect({
|
||||
appState: { targetUrl: window.location.pathname }
|
||||
appState: { targetUrl: window.location.pathname },
|
||||
});
|
||||
};
|
||||
fn();
|
||||
}, [loading, isAuthenticated, loginWithRedirect, path]);
|
||||
|
||||
const render = props =>
|
||||
const render = (props) =>
|
||||
isAuthenticated === true ? <Component {...props} /> : null;
|
||||
|
||||
return <Route path={path} render={render} {...rest} />;
|
||||
|
|
|
|||
Loading…
Reference in a new issue