Skip to content

πŸ“¨ The ultimate agentic social media scheduling tool πŸ€–

feat: chrome extension token in header

Nevo Davidc951720a6e24
diff --git a/apps/extension/manifest.json b/apps/extension/manifest.json
index 132b2fbc4..519fb3428 100755
--- a/apps/extension/manifest.json
+++ b/apps/extension/manifest.json
@@ -14,7 +14,7 @@
"icons": {
"128": "icon-128.png"
},
- "permissions": ["activeTab"],
+ "permissions": ["activeTab", "cookies", "tabs"],
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*", "<all_urls>"],
diff --git a/apps/extension/package.json b/apps/extension/package.json
index 6e3353608..e417706a3 100644
--- a/apps/extension/package.json
+++ b/apps/extension/package.json
@@ -1,12 +1,12 @@
{
"name": "postiz-extension",
- "version": "1.0.1",
+ "version": "1.0.2",
"description": "A simple chrome & firefox extension template with Vite, React, TypeScript and Tailwind CSS.",
"scripts": {
"build": "rm -rf dist && vite build --config vite.config.chrome.ts && zip -r extension.zip dist",
"build:chrome": "vite build --config vite.config.chrome.ts",
"build:firefox": "vite build --config vite.config.firefox.ts",
- "dev": "rm -rf dist && NODE_ENV=development dotenv -e ../../.env -- vite build --config vite.config.chrome.ts --mode development --watch",
+ "dev": "rm -rf dist && dotenv -e ../../.env -- vite build --config vite.config.chrome.ts --mode development --watch",
"dev:chrome": "nodemon --config nodemon.chrome.json",
"dev:firefox": "nodemon --config nodemon.firefox.json"
},
diff --git a/apps/extension/src/pages/background/index.ts b/apps/extension/src/pages/background/index.ts
index fc9c73fa1..f545de5bd 100644
--- a/apps/extension/src/pages/background/index.ts
+++ b/apps/extension/src/pages/background/index.ts
@@ -29,9 +29,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.action === "loadCookie") {
chrome.cookies.get(
{
- url: isDevelopment
- ? "http://localhost:4200"
- : "https://platform.postiz.com",
+ url: import.meta.env?.FRONTEND_URL || process?.env?.FRONTEND_URL,
name: request.cookieName,
},
function (cookies) {
diff --git a/apps/extension/src/pages/content/elements/action.component.tsx b/apps/extension/src/pages/content/elements/action.component.tsx
index 5e0523abd..aad68cc57 100644
--- a/apps/extension/src/pages/content/elements/action.component.tsx
+++ b/apps/extension/src/pages/content/elements/action.component.tsx
@@ -1,8 +1,12 @@
import { FC, memo, useCallback, useEffect, useState } from 'react';
import { ProviderInterface } from '@gitroom/extension/providers/provider.interface';
+import { fetchCookie } from '@gitroom/extension/utils/load.cookie';
-const Comp: FC<{ removeModal: () => void; platform: string, style: string }> = (props) => {
- useEffect(() => {
+const Comp: FC<{ removeModal: () => void; platform: string; style: string }> = (
+ props
+) => {
+ const load = async () => {
+ const cookie = await fetchCookie(`auth`);
if (document.querySelector('iframe#modal-postiz')) {
return;
}
@@ -23,7 +27,9 @@ const Comp: FC<{ removeModal: () => void; platform: string, style: string }> = (
iframe.style.backgroundColor = 'transparent';
// @ts-ignore
iframe.allowTransparency = 'true';
- iframe.src = (import.meta.env?.FRONTEND_URL || process?.env?.FRONTEND_URL) + `/modal/${props.style}/${props.platform}`;
+ iframe.src =
+ (import.meta.env?.FRONTEND_URL || process?.env?.FRONTEND_URL) +
+ `/modal/${props.style}/${props.platform}?loggedAuth=${cookie}`;
iframe.id = 'modal-postiz';
iframe.style.width = '100%';
iframe.style.height = '100%';
@@ -43,6 +49,9 @@ const Comp: FC<{ removeModal: () => void; platform: string, style: string }> = (
}
}
});
+ };
+ useEffect(() => {
+ load();
}, []);
return <></>;
};
@@ -92,7 +101,11 @@ export const ActionComponent: FC<{
<div className="g-wrapper" style={{ position: 'relative' }}>
<div className="absolute left-0 top-0 z-[9999] w-full h-full" />
{modal && (
- <Comp platform={provider.identifier} style={provider.style} removeModal={() => showModal(false)} />
+ <Comp
+ platform={provider.identifier}
+ style={provider.style}
+ removeModal={() => showModal(false)}
+ />
)}
</div>
);
diff --git a/apps/extension/src/utils/request.util.ts b/apps/extension/src/utils/request.util.ts
index 0379965c3..b3b11c8ca 100644
--- a/apps/extension/src/utils/request.util.ts
+++ b/apps/extension/src/utils/request.util.ts
@@ -17,9 +17,7 @@ export const sendRequest = (
export const fetchRequestUtil = async (request: any) => {
return (
await fetch(
- (isDev
- ? "http://localhost:4200/v1/api"
- : "https://platform.postiz.com/v1/api") + request.url,
+ (import.meta.env?.FRONTEND_URL || process?.env?.FRONTEND_URL) + request.url,
{
method: request.method || "GET",
headers: {
diff --git a/apps/extension/vite.config.base.ts b/apps/extension/vite.config.base.ts
index 4ed39db2f..f57633e34 100644
--- a/apps/extension/vite.config.base.ts
+++ b/apps/extension/vite.config.base.ts
@@ -21,7 +21,7 @@ export const baseManifest = {
...manifest,
host_permissions: [
...ProviderList.map((p) => p.baseUrl + "/"),
- isDev ? "http://localhost:4200/" : "https://platform.postiz.com/",
+ import.meta.env?.FRONTEND_URL || process?.env?.FRONTEND_URL + '/*',
],
permissions: [...(manifest.permissions || [])],
content_scripts: [
@@ -29,9 +29,7 @@ export const baseManifest = {
matches: ProviderList.reduce(
(all, p) => [...all, p.baseUrl + "/*"],
[
- isDev
- ? "http://localhost:4200/*"
- : "https://platform.postiz.com/*",
+ import.meta.env?.FRONTEND_URL || process?.env?.FRONTEND_URL + '/*',
],
),
...rest,