Skip to content

Commit e785a01

Browse files
taken suggestion from ai
1 parent b99b6d3 commit e785a01

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

src/components/SecuredRoute/SecuredRoute.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ const SecuredRoute = (): JSX.Element => {
4747
} else if (error) {
4848
return <div>Error During Routing ...</div>;
4949
} else {
50-
console.log('Mocked Data:', data);
51-
if (!data || !data.verifyRole) {
52-
return <div>Error During Routing ...</div>;
50+
if (!data?.verifyRole) {
51+
return <Navigate to="/" replace />;
5352
}
5453
const { isAuthorized = false, role = '' } = (data as VerifyRoleResponse)
5554
.verifyRole;

src/components/UserPortal/SecuredRouteForUser/SecuredRouteForUser.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const SecuredRouteForUser = (): JSX.Element => {
5050
if (!data?.verifyRole) {
5151
return <Navigate to="/" replace />;
5252
}
53-
53+
5454
const { isAuthorized, role } = data.verifyRole;
5555

5656
if (isAuthorized) {

src/screens/PageNotFound/PageNotFound.spec.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,29 @@ import {
1414
ApolloLink,
1515
ApolloProvider,
1616
InMemoryCache,
17+
Observable,
1718
} from '@apollo/client';
1819

1920
const { setItem } = useLocalStorage();
2021

21-
const link = ApolloLink.from([
22-
new ApolloLink((operation, forward) => {
23-
return forward ? forward(operation) : null; // ✅ Fix the issue
24-
}),
25-
]);
22+
const link = new ApolloLink((operation, forward) => {
23+
// Mock responses based on the operation
24+
if (operation.operationName === 'VERIFY_ROLE') {
25+
return new Observable((observer) => {
26+
// Simulate different authorization scenarios
27+
observer.next({
28+
data: {
29+
verifyRole: {
30+
isAuthorized: true, // or false for different test cases
31+
role: 'ADMIN', // or other roles
32+
},
33+
},
34+
});
35+
observer.complete();
36+
});
37+
}
38+
return forward(operation);
39+
});
2640

2741
const client: ApolloClient<NormalizedCacheObject> = new ApolloClient({
2842
cache: new InMemoryCache(),

0 commit comments

Comments
 (0)