File tree Expand file tree Collapse file tree 3 files changed +3
-28
lines changed Expand file tree Collapse file tree 3 files changed +3
-28
lines changed Original file line number Diff line number Diff line change @@ -173,7 +173,7 @@ export default MyComponent;
173173import React from " react" ;
174174import { Router , Route , Switch } from " react-router-dom" ;
175175import { createBrowserHistory } from " history" ;
176- import { WarrantProvider , ProtectedRoute , WARRANT_IGNORE_ID } from " @warrantdev/react-warrant-js" ;
176+ import { WarrantProvider , ProtectedRoute } from " @warrantdev/react-warrant-js" ;
177177import PublicPage from " ./PublicPage" ;
178178import ProtectedPage from " ./ProtectedPage" ;
179179
@@ -227,28 +227,6 @@ const MyComponent = () => {
227227export default MyComponent ;
228228```
229229
230- ** NOTE:** To ignore the ` objectId ` when using any of the provided components, you can pass the constant ` WARRANT_IGNORE_ID ` . You must have a corresponding warrant that grants access to ** ANY** user on the given ` objectType ` for this check to succeed.
231- ``` jsx
232- import React from " react" ;
233- import { ProtectedComponent , WARRANT_IGNORE_ID } from " @warrantdev/react-warrant-js" ;
234-
235- const MyComponent = () => {
236- return < div>
237- < MyPublicComponent/ >
238- {/* Only shows MyProtectedComponent if the user can "view" ANY myObject */ }
239- < ProtectedComponent
240- objectType= " myObject"
241- objectId= {WARRANT_IGNORE_ID }
242- relation= " view"
243- >
244- < MyProtectedComponent/ >
245- < / ProtectedComponent>
246- < / div> ;
247- };
248-
249- export default MyComponent ;
250- ```
251-
252230### ` withWarrant `
253231Use the ` withWarrant ` Higher Order Component (HOC) to protect components that should only be accessible to users with certain privileges.
254232
Original file line number Diff line number Diff line change 11import React , { useEffect , useState } from "react" ;
22import { Redirect , Route , RouteProps } from "react-router-dom" ;
3- import { WARRANT_IGNORE_ID , WarrantCheck } from "@warrantdev/warrant-js" ;
3+ import { WarrantCheck } from "@warrantdev/warrant-js" ;
44import useWarrant from "./useWarrant" ;
55
66export interface ProtectedRouteOptions extends WarrantCheck {
@@ -32,9 +32,7 @@ const ProtectedRoute: React.FunctionComponent<ProtectedRouteProps> = ({
3232
3333 if ( sessionToken ) {
3434 warrants . forEach ( ( warrant ) => {
35- if ( warrant . objectId === WARRANT_IGNORE_ID ) {
36- warrant . objectId = WARRANT_IGNORE_ID ;
37- } else if ( computedMatch . params [ warrant . objectId ] ) {
35+ if ( computedMatch . params [ warrant . objectId ] ) {
3836 /** @ts -ignore */
3937 warrant . objectId = computedMatch . params [ warrant . objectId ] ;
4038 }
Original file line number Diff line number Diff line change @@ -4,4 +4,3 @@ export { default as WarrantProvider } from "./WarrantProvider";
44export { default as useWarrant } from "./useWarrant" ;
55export { default as ProtectedComponent } from "./ProtectedComponent" ;
66export { default as ProtectedRoute } from "./ProtectedRoute" ;
7- export { WARRANT_IGNORE_ID } from "@warrantdev/warrant-js" ;
You can’t perform that action at this time.
0 commit comments