diff options
author | Anton Tananaev <anton@traccar.org> | 2022-08-17 09:22:41 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-08-17 09:22:41 -0700 |
commit | aa72fc6dbe2be7e3322a8a6110a6997435a0679a (patch) | |
tree | 2f01781678971fa34e0b0a2fea3373d8f1bc4e44 /modern | |
parent | 1184b5902be66c474f904fdbd8deb4445f4fc092 (diff) | |
download | trackermap-web-aa72fc6dbe2be7e3322a8a6110a6997435a0679a.tar.gz trackermap-web-aa72fc6dbe2be7e3322a8a6110a6997435a0679a.tar.bz2 trackermap-web-aa72fc6dbe2be7e3322a8a6110a6997435a0679a.zip |
Remove notification token on logout
Diffstat (limited to 'modern')
-rw-r--r-- | modern/src/common/components/BottomMenu.js | 27 | ||||
-rw-r--r-- | modern/src/common/components/NativeInterface.js | 1 |
2 files changed, 25 insertions, 3 deletions
diff --git a/modern/src/common/components/BottomMenu.js b/modern/src/common/components/BottomMenu.js index b0cd5e84..3ef464e0 100644 --- a/modern/src/common/components/BottomMenu.js +++ b/modern/src/common/components/BottomMenu.js @@ -23,13 +23,13 @@ const BottomMenu = () => { const readonly = useRestriction('readonly'); const disableReports = useRestriction('disableReports'); - const userId = useSelector((state) => state.session.user.id); + const user = useSelector((state) => state.session.user); const socket = useSelector((state) => state.session.socket); const [anchorEl, setAnchorEl] = useState(null); const currentSelection = () => { - if (location.pathname === `/settings/user/${userId}`) { + if (location.pathname === `/settings/user/${user.id}`) { return 'account'; } if (location.pathname.startsWith('/settings')) { return 'settings'; @@ -43,11 +43,32 @@ const BottomMenu = () => { const handleAccount = () => { setAnchorEl(null); - navigate(`/settings/user/${userId}`); + navigate(`/settings/user/${user.id}`); }; const handleLogout = async () => { setAnchorEl(null); + + const notificationToken = window.localStorage.getItem('notificationToken'); + if (notificationToken) { + window.localStorage.removeItem('notificationToken'); + const tokens = user.attributes.notificationTokens?.split(',') || []; + if (tokens.includes(notificationToken)) { + const updatedUser = { + ...user, + attributes: { + ...user.attributes, + notificationTokens: tokens.filter((it) => it !== notificationToken).join(','), + }, + }; + await fetch(`/api/users/${user.id}`, { + method: 'PUT', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(updatedUser), + }); + } + } + await fetch('/api/session', { method: 'DELETE' }); navigate('/login'); dispatch(sessionActions.updateUser(null)); diff --git a/modern/src/common/components/NativeInterface.js b/modern/src/common/components/NativeInterface.js index b36a3d26..d36b64c5 100644 --- a/modern/src/common/components/NativeInterface.js +++ b/modern/src/common/components/NativeInterface.js @@ -33,6 +33,7 @@ const NativeInterface = () => { useEffectAsync(async () => { if (user && token) { + window.localStorage.setItem('notificationToken', token); setToken(null); const tokens = user.attributes.notificationTokens?.split(',') || []; |