fix: user has to login every time chrome sidepanel is opened (#5544)
We can pass the auth tokens to our front app via post message, which will also allow us to pass route names to navigate on it
This commit is contained in:
@ -5,10 +5,23 @@ import { isDefined } from '~/utils/isDefined';
|
||||
// Inject buttons into the DOM when SPA is reloaded on the resource url.
|
||||
// e.g. reload the page when on https://www.linkedin.com/in/mabdullahabaid/
|
||||
// await insertButtonForCompany();
|
||||
(async () => {
|
||||
await insertButtonForCompany();
|
||||
await insertButtonForPerson();
|
||||
})();
|
||||
|
||||
const companyRoute = /^https?:\/\/(?:www\.)?linkedin\.com\/company(?:\/\S+)?/;
|
||||
const personRoute = /^https?:\/\/(?:www\.)?linkedin\.com\/in(?:\/\S+)?/;
|
||||
|
||||
const executeScript = async () => {
|
||||
const loc = window.location.href;
|
||||
switch (true) {
|
||||
case companyRoute.test(loc):
|
||||
await insertButtonForCompany();
|
||||
break;
|
||||
case personRoute.test(loc):
|
||||
await insertButtonForPerson();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
// The content script gets executed upon load, so the the content script is executed when a user visits https://www.linkedin.com/feed/.
|
||||
// However, there would never be another reload in a single page application unless triggered manually.
|
||||
@ -16,8 +29,7 @@ import { isDefined } from '~/utils/isDefined';
|
||||
// e.g. create "Add to Twenty" button when a user navigates to https://www.linkedin.com/in/mabdullahabaid/ from https://www.linkedin.com/feed/
|
||||
chrome.runtime.onMessage.addListener(async (message, _, sendResponse) => {
|
||||
if (message.action === 'executeContentScript') {
|
||||
await insertButtonForCompany();
|
||||
await insertButtonForPerson();
|
||||
await executeScript();
|
||||
}
|
||||
|
||||
sendResponse('Executing!');
|
||||
@ -26,8 +38,7 @@ chrome.runtime.onMessage.addListener(async (message, _, sendResponse) => {
|
||||
chrome.storage.local.onChanged.addListener(async (store) => {
|
||||
if (isDefined(store.accessToken)) {
|
||||
if (isDefined(store.accessToken.newValue)) {
|
||||
await insertButtonForCompany();
|
||||
await insertButtonForPerson();
|
||||
await executeScript();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user