-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: GitHub page update listener (#37)
* feat: gh-page-update-listener * fix: Updated GH username matcher to ignore query params * chore: Added auth-cookie-change handler * chore: Removed debug comments --------- Co-authored-by: Brian Douglas <[email protected]>
- Loading branch information
Showing
5 changed files
with
38 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,28 @@ | ||
import { SUPABASE_LOGOUT_URL, OPEN_SAUCED_AUTH_TOKEN_KEY } from "../constants"; | ||
import { SUPABASE_LOGOUT_URL, SUPABASE_AUTH_DOMAIN, SUPABASE_COOKIE_NAME, OPEN_SAUCED_AUTH_TOKEN_KEY } from "../constants"; | ||
import { checkTokenValidity } from "../utils/fetchOpenSaucedApiData"; | ||
import setAccessTokenInChromeStorage from "../utils/setAccessToken"; | ||
|
||
chrome.webRequest.onCompleted.addListener( | ||
(details) => { | ||
chrome.storage.sync.remove(OPEN_SAUCED_AUTH_TOKEN_KEY); | ||
}, | ||
{ urls: [SUPABASE_LOGOUT_URL] } | ||
); | ||
(details) => { | ||
chrome.storage.sync.remove(OPEN_SAUCED_AUTH_TOKEN_KEY); | ||
}, | ||
{ urls: [SUPABASE_LOGOUT_URL] } | ||
); | ||
|
||
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo) { | ||
if (changeInfo.url?.includes("github.com")) { | ||
chrome.tabs.sendMessage(tabId, { message: "GITHUB_URL_CHANGED" }); | ||
} | ||
}); | ||
|
||
chrome.cookies.onChanged.addListener(async (changeInfo) => { | ||
try { | ||
if (changeInfo.cookie.name != SUPABASE_COOKIE_NAME || changeInfo.cookie.domain != SUPABASE_AUTH_DOMAIN) return; | ||
if (changeInfo.removed) return chrome.storage.sync.remove(OPEN_SAUCED_AUTH_TOKEN_KEY); | ||
const isValidToken = await checkTokenValidity(changeInfo.cookie.value) | ||
if (!isValidToken) return chrome.storage.sync.remove(OPEN_SAUCED_AUTH_TOKEN_KEY); | ||
setAccessTokenInChromeStorage(changeInfo.cookie.value); | ||
} catch(error) { | ||
console.error("Error processing cookie update:", error); | ||
} | ||
}) |