Skip to content

Commit f14a658

Browse files
committed
Refactor unauthorized alert handling to use popup store and improve logout confirmation message
1 parent d5697c3 commit f14a658

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

src/query/index.ts

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { navigationStore } from '@/zustand/navigationStore'
2+
import popupStore from '@/zustand/popupStore'
23
import NetInfo from '@react-native-community/netinfo'
34
import { useFocusEffect } from '@react-navigation/native'
5+
import { logout } from '@screens/auth/utils'
46
import { onlineManager, QueryClient, type NotifyOnChangeProps } from '@tanstack/react-query'
57
import React from 'react'
6-
import { Alert } from 'react-native'
78

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

105106
function handleUnauthorized(data: ServerResponse) {
106107
if (data.message !== 'Unauthorized') return
107-
navigation?.reset({
108-
index: 0,
109-
routes: [{ name: 'Login' }],
110-
})
111-
Alert.alert('Unauthorized', 'Please login again', [
112-
{
113-
text: 'OK',
114-
onPress: () => {
115-
navigation?.reset({
116-
index: 0,
117-
routes: [{ name: 'Login' }],
118-
})
119-
},
120-
},
121-
])
108+
const alert = popupStore.getState().alert
109+
alert('Unauthorized', 'Your session has expired. Please login again.', [{ text: 'OK', onPress: logout }])
122110
}

src/screens/auth/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function logout() {
1313

1414
export function handleLogout(logoutMutation: () => void) {
1515
const alert = popupStore.getState().alert
16-
alert('Log out', 'This is the device you are currently using. Are you sure you want to log out?', [
16+
alert('Log out', 'Are you sure you want to log out from this device?', [
1717
{
1818
text: 'Log out',
1919
onPress() {

0 commit comments

Comments
 (0)