aboutsummaryrefslogtreecommitdiff
path: root/modern/src/common/components/NativeInterface.js
diff options
context:
space:
mode:
Diffstat (limited to 'modern/src/common/components/NativeInterface.js')
-rw-r--r--modern/src/common/components/NativeInterface.js34
1 files changed, 18 insertions, 16 deletions
diff --git a/modern/src/common/components/NativeInterface.js b/modern/src/common/components/NativeInterface.js
index aee4c042..b36a3d26 100644
--- a/modern/src/common/components/NativeInterface.js
+++ b/modern/src/common/components/NativeInterface.js
@@ -36,24 +36,26 @@ const NativeInterface = () => {
setToken(null);
const tokens = user.attributes.notificationTokens?.split(',') || [];
- const updatedUser = {
- ...user,
- attributes: {
- ...user.attributes,
- notificationTokens: [...tokens.slice(-2), token].join(','),
- },
- };
+ if (!tokens.includes(token)) {
+ const updatedUser = {
+ ...user,
+ attributes: {
+ ...user.attributes,
+ notificationTokens: [...tokens.slice(-2), token].join(','),
+ },
+ };
- const response = await fetch(`/api/users/${user.id}`, {
- method: 'PUT',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify(updatedUser),
- });
+ const response = await fetch(`/api/users/${user.id}`, {
+ method: 'PUT',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify(updatedUser),
+ });
- if (response.ok) {
- dispatch(sessionActions.updateUser(await response.json()));
- } else {
- throw Error(await response.text());
+ if (response.ok) {
+ dispatch(sessionActions.updateUser(await response.json()));
+ } else {
+ throw Error(await response.text());
+ }
}
}
}, [user, token, setToken]);