PrivateRoute and API protected

This commit is contained in:
Ruidy Nemausat 2020-04-19 09:42:20 +02:00
parent 7115d28044
commit f23bfad793
5 changed files with 7 additions and 8 deletions

View file

@ -13,7 +13,7 @@ using TicketManager.Resources;
namespace TicketManager.Controllers
{
// [Authorize]
[Authorize]
[Produces("application/json")]
[Route("api/v1/users")]
[ApiController]

View file

@ -13,7 +13,7 @@ using System;
namespace TicketManager.Controllers
{
// [Authorize(Roles = "Admin")]
// [Authorize]
[Authorize]
[Produces("application/json")]
[Route("api/v1/[controller]")]
[ApiController]

View file

@ -10,7 +10,7 @@ using TicketManager.Models;
namespace TicketManager.Controllers
{
// [Authorize]
[Authorize]
[Route("api/v1/[controller]")]
[ApiController]
public class TicketsController : ControllerBase

View file

@ -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 />

View file

@ -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} />;