File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed
Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change 1+ import { navigationStore } from '@/zustand/navigationStore'
12import NetInfo from '@react-native-community/netinfo'
23import { useFocusEffect } from '@react-navigation/native'
34import { onlineManager , QueryClient , type NotifyOnChangeProps } from '@tanstack/react-query'
45import React from 'react'
6+ import { Alert } from 'react-native'
57
68// Online Status Manager
79onlineManager . setEventListener ( ( setOnline ) => {
@@ -79,14 +81,41 @@ export function useQueryFocusAware() {
7981 return ( ) => focusedRef . current
8082}
8183
84+ type ServerResponse = {
85+ message : string
86+ status : boolean
87+ }
88+ const navigation = navigationStore . getState ( ) . navigation
8289export const queryClient = new QueryClient ( {
8390 defaultOptions : {
84- queries : { } ,
91+ queries : {
92+ select ( data ) {
93+ console . log ( data )
94+ handleUnauthorized ( data as ServerResponse )
95+ return data
96+ } ,
97+ } ,
8598 mutations : {
8699 onSuccess : ( data ) => {
87100 console . log ( data )
88- console . log ( 'Mutation Success' )
101+ handleUnauthorized ( data as ServerResponse )
89102 } ,
90103 } ,
91104 } ,
92105} )
106+
107+ function handleUnauthorized ( data : ServerResponse ) {
108+ if ( data . message !== 'Unauthorized' ) return
109+ navigation ?. reset ( {
110+ index : 0 ,
111+ routes : [ { name : 'Login' } ] ,
112+ } )
113+ Alert . alert ( 'Unauthorized' , 'Please login again' , [
114+ {
115+ text : 'OK' ,
116+ onPress : ( ) => {
117+ navigation ?. navigate ( 'Login' )
118+ } ,
119+ } ,
120+ ] )
121+ }
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ export default function Devices({ navigation }: NavProp) {
6969 < >
7070 { data . data . devices . map ( ( device , i ) => (
7171 < Animated . View key = { device ?. id } entering = { delayedFadeAnimation ( i ) } >
72- < Device key = { i } navigation = { navigation } device = { device } isSelf />
72+ < Device key = { i } navigation = { navigation } device = { device } isSelf = { false } />
7373 </ Animated . View >
7474 ) ) }
7575 </ >
You can’t perform that action at this time.
0 commit comments