mirror of
https://github.com/rjNemo/ticket_manager
synced 2026-06-11 19:26:40 +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
|
namespace TicketManager.Controllers
|
||||||
{
|
{
|
||||||
// [Authorize]
|
[Authorize]
|
||||||
[Produces("application/json")]
|
[Produces("application/json")]
|
||||||
[Route("api/v1/users")]
|
[Route("api/v1/users")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ using System;
|
||||||
namespace TicketManager.Controllers
|
namespace TicketManager.Controllers
|
||||||
{
|
{
|
||||||
// [Authorize(Roles = "Admin")]
|
// [Authorize(Roles = "Admin")]
|
||||||
// [Authorize]
|
[Authorize]
|
||||||
[Produces("application/json")]
|
[Produces("application/json")]
|
||||||
[Route("api/v1/[controller]")]
|
[Route("api/v1/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ using TicketManager.Models;
|
||||||
|
|
||||||
namespace TicketManager.Controllers
|
namespace TicketManager.Controllers
|
||||||
{
|
{
|
||||||
// [Authorize]
|
[Authorize]
|
||||||
[Route("api/v1/[controller]")]
|
[Route("api/v1/[controller]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class TicketsController : ControllerBase
|
public class TicketsController : ControllerBase
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,12 @@ import { UserController } from "../controllers/UserController";
|
||||||
import { TicketController } from "../controllers/TicketController";
|
import { TicketController } from "../controllers/TicketController";
|
||||||
import { NotFoundPage } from "../pages/NotFoundPage";
|
import { NotFoundPage } from "../pages/NotFoundPage";
|
||||||
import { TestPage } from "../pages/TestPage";
|
import { TestPage } from "../pages/TestPage";
|
||||||
|
import { PrivateRoute } from "./PrivateRoute";
|
||||||
|
|
||||||
export const AppRouter = () => {
|
export const AppRouter = () => {
|
||||||
return (
|
return (
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route exact path="/test">
|
<PrivateRoute path="/test" component={TestPage} />
|
||||||
<TestPage />
|
|
||||||
</Route>
|
|
||||||
|
|
||||||
<Route exact path="/">
|
<Route exact path="/">
|
||||||
<HomeController />
|
<HomeController />
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,13 @@ export const PrivateRoute = ({ component: Component, path, ...rest }) => {
|
||||||
}
|
}
|
||||||
const fn = async () => {
|
const fn = async () => {
|
||||||
await loginWithRedirect({
|
await loginWithRedirect({
|
||||||
appState: { targetUrl: window.location.pathname }
|
appState: { targetUrl: window.location.pathname },
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
fn();
|
fn();
|
||||||
}, [loading, isAuthenticated, loginWithRedirect, path]);
|
}, [loading, isAuthenticated, loginWithRedirect, path]);
|
||||||
|
|
||||||
const render = props =>
|
const render = (props) =>
|
||||||
isAuthenticated === true ? <Component {...props} /> : null;
|
isAuthenticated === true ? <Component {...props} /> : null;
|
||||||
|
|
||||||
return <Route path={path} render={render} {...rest} />;
|
return <Route path={path} render={render} {...rest} />;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue