From ae036995bf1284056a94dbf15bd8972f76e08988 Mon Sep 17 00:00:00 2001 From: Fosco Marotto Date: Tue, 9 Feb 2021 11:16:04 -0500 Subject: [PATCH] Fix authorization header when no access token --- .../service_worker/web_push_notifications.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/javascript/gabsocial/service_worker/web_push_notifications.js b/app/javascript/gabsocial/service_worker/web_push_notifications.js index 4eabf949..36669121 100644 --- a/app/javascript/gabsocial/service_worker/web_push_notifications.js +++ b/app/javascript/gabsocial/service_worker/web_push_notifications.js @@ -40,12 +40,13 @@ const notify = options => const fetchFromApi = (path, method, accessToken) => { const url = (new URL(path, self.location)).href; + let headers = { + 'Authorization': `Bearer ${accessToken}`, + 'Content-Type': 'application/json', + } + if (!accessToken) { delete headers['Authorization'] } return fetch(url, { - headers: { - 'Authorization': `Bearer ${accessToken}`, - 'Content-Type': 'application/json', - }, - + headers: headers, method: method, credentials: 'include', }).then(res => {