File tree Expand file tree Collapse file tree 3 files changed +22
-9
lines changed
UserPortal/SecuredRouteForUser Expand file tree Collapse file tree 3 files changed +22
-9
lines changed Original file line number Diff line number Diff line change @@ -47,9 +47,8 @@ const SecuredRoute = (): JSX.Element => {
47
47
} else if ( error ) {
48
48
return < div > Error During Routing ...</ div > ;
49
49
} 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 /> ;
53
52
}
54
53
const { isAuthorized = false , role = '' } = ( data as VerifyRoleResponse )
55
54
. verifyRole ;
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ const SecuredRouteForUser = (): JSX.Element => {
50
50
if ( ! data ?. verifyRole ) {
51
51
return < Navigate to = "/" replace /> ;
52
52
}
53
-
53
+
54
54
const { isAuthorized, role } = data . verifyRole ;
55
55
56
56
if ( isAuthorized ) {
Original file line number Diff line number Diff line change @@ -14,15 +14,29 @@ import {
14
14
ApolloLink ,
15
15
ApolloProvider ,
16
16
InMemoryCache ,
17
+ Observable ,
17
18
} from '@apollo/client' ;
18
19
19
20
const { setItem } = useLocalStorage ( ) ;
20
21
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
+ } ) ;
26
40
27
41
const client : ApolloClient < NormalizedCacheObject > = new ApolloClient ( {
28
42
cache : new InMemoryCache ( ) ,
You can’t perform that action at this time.
0 commit comments