Skip to content

Commit

Permalink
Refactor unauthorized alert handling to use popup store and improve l…
Browse files Browse the repository at this point in the history
…ogout confirmation message
  • Loading branch information
codeAbinash committed Jan 13, 2025
1 parent d5697c3 commit f14a658
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
20 changes: 4 additions & 16 deletions src/query/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { navigationStore } from '@/zustand/navigationStore'
import popupStore from '@/zustand/popupStore'
import NetInfo from '@react-native-community/netinfo'
import { useFocusEffect } from '@react-navigation/native'
import { logout } from '@screens/auth/utils'
import { onlineManager, QueryClient, type NotifyOnChangeProps } from '@tanstack/react-query'
import React from 'react'
import { Alert } from 'react-native'

// Online Status Manager
onlineManager.setEventListener((setOnline) => {
Expand Down Expand Up @@ -104,19 +105,6 @@ export const queryClient = new QueryClient({

function handleUnauthorized(data: ServerResponse) {
if (data.message !== 'Unauthorized') return
navigation?.reset({
index: 0,
routes: [{ name: 'Login' }],
})
Alert.alert('Unauthorized', 'Please login again', [
{
text: 'OK',
onPress: () => {
navigation?.reset({
index: 0,
routes: [{ name: 'Login' }],
})
},
},
])
const alert = popupStore.getState().alert
alert('Unauthorized', 'Your session has expired. Please login again.', [{ text: 'OK', onPress: logout }])
}
2 changes: 1 addition & 1 deletion src/screens/auth/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function logout() {

export function handleLogout(logoutMutation: () => void) {
const alert = popupStore.getState().alert
alert('Log out', 'This is the device you are currently using. Are you sure you want to log out?', [
alert('Log out', 'Are you sure you want to log out from this device?', [
{
text: 'Log out',
onPress() {
Expand Down

0 comments on commit f14a658

Please sign in to comment.