aboutsummaryrefslogtreecommitdiff
path: root/modern
diff options
context:
space:
mode:
Diffstat (limited to 'modern')
-rw-r--r--modern/src/index.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/modern/src/index.js b/modern/src/index.js
index 32cf990..c7123ed 100644
--- a/modern/src/index.js
+++ b/modern/src/index.js
@@ -16,4 +16,34 @@ ReactDOM.render((
</Provider>
), document.getElementById('root'));
+window.updateNotificationToken = async (token) => {
+ // Get user attributes
+ const response = await fetch('/api/session', {
+ headers: { Accept: 'application/json' }
+ });
+ if (response.ok) {
+ let user = await response.json();
+ if (user.attributes) {
+ if (!user.attributes.notificationTokens || user.attributes.notificationTokens.indexOf(token) < 0) {
+ if (!user.attributes.notificationTokens) {
+ user.attributes.notificationTokens = token;
+ } else {
+ user.attributes.notificationTokens += ',' + token;
+ }
+
+ // Set user attributes
+ const response2 = await fetch(`/api/users/${user.id}`, {
+ method: 'PUT',
+ headers: {
+ Accept: 'application/json',
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify(user),
+ });
+ console.log ('Set token: ', await response2.json());
+ }
+ }
+ }
+}
+
serviceWorker.unregister();