Skip to content

Commit eeca3c1

Browse files
committed
fix(mobile): clear push token on logout The-Commit-Company#1684
1 parent 8963ce7 commit eeca3c1

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

apps/mobile/hooks/useLogout.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,32 @@ import { toast } from 'sonner-native';
77
import { useSetAtom } from 'jotai';
88
import { selectedWorkspaceFamily } from './useGetCurrentWorkspace';
99
import useSiteContext from './useSiteContext';
10+
import { getMessaging } from '@react-native-firebase/messaging';
11+
12+
const messaging = getMessaging()
1013

1114

1215
export const useLogout = () => {
1316
const siteInformation = useSiteContext()
14-
const { tokenParams } = useContext(FrappeContext) as FrappeConfig
17+
const { tokenParams, call } = useContext(FrappeContext) as FrappeConfig
1518

1619
const setSelectedWorkspace = useSetAtom(selectedWorkspaceFamily(siteInformation?.sitename || ''))
1720

1821
const logout = () => {
1922
// Remove the current site from AsyncStorage
2023
// Revoke the token
2124
// Redirect to the landing page
25+
try {
26+
messaging.getToken().then((token) => {
27+
if (token) {
28+
call.post('raven.api.notification.unsubscribe', {
29+
fcm_token: token
30+
})
31+
}
32+
})
33+
} catch (error) {
34+
console.error(error)
35+
}
2236
setSelectedWorkspace('')
2337
clearDefaultSite()
2438
.then(() => {

apps/mobile/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"@expo/dom-webview": "^0.0.2",
1616
"@expo/react-native-action-sheet": "^4.1.0",
1717
"@gorhom/bottom-sheet": "5.0.6",
18-
"@legendapp/list": "^1.0.11",
18+
"@legendapp/list": "^1.0.13",
1919
"@raven/lib": "*",
2020
"@react-native-async-storage/async-storage": "1.23.1",
2121
"@react-native-firebase/app": "^21.11.0",

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,10 +2609,10 @@
26092609
resolved "https://registry.yarnpkg.com/@jsamr/react-native-li/-/react-native-li-2.3.1.tgz#12a5b5f6e3971cec77b96bee58104eed0ae9314a"
26102610
integrity sha512-Qbo4NEj48SQ4k8FZJHFE2fgZDKTWaUGmVxcIQh3msg5JezLdTMMHuRRDYctfdHI6L0FZGObmEv3haWbIvmol8w==
26112611

2612-
"@legendapp/list@^1.0.11":
2613-
version "1.0.11"
2614-
resolved "https://registry.yarnpkg.com/@legendapp/list/-/list-1.0.11.tgz#71641aad790f0c02c26542e4ac2d9930bd62301e"
2615-
integrity sha512-A1DK2Buqvev2c1nV77/M0Xnft5aIX+7AmUbLY/meHiK5SI98hX7qq3U1VSDHUbrk7fPOD1Skdt2F3THwRy9Ijw==
2612+
"@legendapp/list@^1.0.13":
2613+
version "1.0.13"
2614+
resolved "https://registry.yarnpkg.com/@legendapp/list/-/list-1.0.13.tgz#bfca62d4243b448b43120c1d25807534dae846a7"
2615+
integrity sha512-qTFbWEvdNM0wA7voVL+l+NLC8NfFmyqh/QvFratMiA5XImW2BPqN79Qq1x56SIVWnxxakHPjaW8J2wE0p+qMDQ==
26162616
dependencies:
26172617
use-sync-external-store "^1.5.0"
26182618

0 commit comments

Comments
 (0)