Skip to content

Commit ede7b00

Browse files
authored
Merge pull request #7 from warrant-dev/FixWarrantsProcessing
Deep clone warrants array before processing
2 parents 0e1d146 + e9475b0 commit ede7b00

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/ProtectedRoute.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ const ProtectedRoute: React.FunctionComponent<ProtectedRouteProps> = ({
3131
};
3232

3333
if (sessionToken) {
34-
warrants.forEach((warrant) => {
34+
let warrantsToCheck = [...warrants].map(warrant => ({...warrant}));
35+
warrantsToCheck.forEach((warrant) => {
3536
if (computedMatch.params[warrant.objectId]) {
3637
/** @ts-ignore */
3738
warrant.objectId = computedMatch.params[warrant.objectId];
@@ -42,7 +43,7 @@ const ProtectedRoute: React.FunctionComponent<ProtectedRouteProps> = ({
4243
}
4344
})
4445

45-
checkForWarrant({ op, warrants });
46+
checkForWarrant({ op, warrants: warrantsToCheck });
4647
}
4748
}, [sessionToken]);
4849

src/withWarrant.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import React, { useEffect, useState } from "react";
22
import { WarrantCheck } from "@warrantdev/warrant-js";
33
import useWarrant from "./useWarrant";
44

5-
export interface WithWarrantOptions {
6-
warrantCheck: WarrantCheck;
5+
export interface WithWarrantOptions extends WarrantCheck {
76
redirectTo: string;
87
}
98

@@ -16,13 +15,13 @@ export interface WithWarrantOptions {
1615
*/
1716
const withWarrant = (WrappedComponent: React.ComponentClass, options: WithWarrantOptions) => {
1817
return (props: any) => {
19-
const { warrantCheck, redirectTo } = options;
18+
const { op, warrants, redirectTo } = options;
2019
const { sessionToken, hasWarrant } = useWarrant();
2120
const [showWrappedComponent, setShowWrappedComponent] = useState<boolean>(false);
2221

2322
useEffect(() => {
2423
const checkWarrant = async () => {
25-
setShowWrappedComponent(await hasWarrant(warrantCheck));
24+
setShowWrappedComponent(await hasWarrant({ op, warrants }));
2625
};
2726

2827
if (sessionToken) {

0 commit comments

Comments
 (0)