Skip to content

Commit 8e9fc54

Browse files
committed
fix: syncing incomplete cookies w db
1 parent 7a0f87b commit 8e9fc54

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "halo-discord-extension",
3-
"version": "2.0.3",
3+
"version": "2.0.4",
44
"description": "Receive Discord notifications for updates in Halo",
55
"author": "Elijah Olmos",
66
"license": "AGPL-3.0-only",

src/background.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { child, ref, set } from 'firebase/database';
2121
import { init, stores } from './stores';
2222
import { triggerDiscordAuthFlow } from './util/auth';
2323
import chromeStorageSyncStore from './util/chromeStorageSyncStore';
24-
import { getHaloUserInfo } from './util/halo';
24+
import { AUTHORIZATION_KEY, CONTEXT_KEY, getHaloUserInfo } from './util/halo';
2525
import { auth, db, getHaloCookies } from './util/util';
2626
// no stores - code is not shared between background and popup
2727

@@ -85,7 +85,7 @@ const firebaseSignIn = async function () {
8585
//halo_cookies.set(await getHaloCookies()); //should be unnecessary w initial_value
8686

8787
chrome.runtime.onInstalled.addListener(({ reason }) => {
88-
console.log('onInstalled', reason)
88+
console.log('onInstalled', reason);
8989
switch (reason) {
9090
case chrome.runtime.OnInstalledReason.INSTALL:
9191
// currently broken, see https://github.com/GoogleChrome/developer.chrome.com/issues/2602
@@ -150,7 +150,14 @@ const firebaseSignIn = async function () {
150150

151151
//retrieve new cookies and merge w old ones
152152
const cookies = await getHaloCookies();
153-
if(!cookies || !Object.keys(cookies).length) return; //don't push empty cookies
153+
if (
154+
!cookies ||
155+
!Object.keys(cookies).length ||
156+
!cookies.hasOwnProperty(AUTHORIZATION_KEY) ||
157+
!cookies.hasOwnProperty(CONTEXT_KEY)
158+
)
159+
//don't push empty cookies or cookies without both cookies
160+
return;
154161
stores.halo_cookies.update(cookies);
155162
//push to db
156163
await set(ref(db, `cookies/${auth.currentUser.uid}`), cookies);

0 commit comments

Comments
 (0)