From e37af30888f0c35fe7639937473a09d727175a27 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 23 Dec 2024 23:26:31 -0500 Subject: [PATCH 1/3] Update gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3c787de..60c8a59 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,5 @@ dist-ssr *.sw? .env dashboard/build/** -dashboard-server/frontend/build/** \ No newline at end of file +dashboard-server/frontend/build/** +._* \ No newline at end of file From 9218d0a0db1243e0e25153a61f6db53c2d89acc0 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 23 Dec 2024 23:37:44 -0500 Subject: [PATCH 2/3] Fix local network authentication --- dashboard-server/auth-server/index.js | 28 ++++++++++++++++----------- dashboard/vite.config.js | 24 ++++++++++++++++++++--- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/dashboard-server/auth-server/index.js b/dashboard-server/auth-server/index.js index d191bce..5e81177 100644 --- a/dashboard-server/auth-server/index.js +++ b/dashboard-server/auth-server/index.js @@ -38,7 +38,13 @@ const corsOptions = { console.log('CORS check for origin:', origin); - // Check if origin is allowed + // Allow local network IPs (192.168.1.xxx) + if (origin && origin.match(/^http:\/\/192\.168\.1\.\d{1,3}(:\d+)?$/)) { + callback(null, true); + return; + } + + // Check if origin is in allowed list if (!origin || allowedOrigins.indexOf(origin) !== -1) { callback(null, true); } else { @@ -96,19 +102,19 @@ app.post('/login', (req, res) => { expiresIn: '24h' }); - // Determine if request is from localhost - const isLocalhost = req.headers.origin?.includes('localhost'); + // Determine if request is from local network + const isLocalNetwork = req.headers.origin?.includes('192.168.1.') || req.headers.origin?.includes('localhost'); const cookieOptions = { httpOnly: true, - secure: !isLocalhost, - sameSite: isLocalhost ? 'lax' : 'none', + secure: !isLocalNetwork, // Only use secure for non-local requests + sameSite: isLocalNetwork ? 'lax' : 'none', path: '/', maxAge: 24 * 60 * 60 * 1000 // 24 hours }; - // Add domain only for production - if (!isLocalhost) { + // Only set domain for production + if (!isLocalNetwork) { cookieOptions.domain = '.kent.pw'; } @@ -163,13 +169,13 @@ app.get('/check', (req, res) => { }); app.post('/logout', (req, res) => { - const isLocalhost = req.headers.origin?.includes('localhost'); + const isLocalNetwork = req.headers.origin?.includes('192.168.1.') || req.headers.origin?.includes('localhost'); const cookieOptions = { httpOnly: true, - secure: !isLocalhost, - sameSite: isLocalhost ? 'lax' : 'none', + secure: !isLocalNetwork, + sameSite: isLocalNetwork ? 'lax' : 'none', path: '/', - domain: isLocalhost ? undefined : '.kent.pw' + domain: isLocalNetwork ? undefined : '.kent.pw' }; console.log('Clearing cookie with options:', cookieOptions); diff --git a/dashboard/vite.config.js b/dashboard/vite.config.js index d56e1b6..2983c10 100644 --- a/dashboard/vite.config.js +++ b/dashboard/vite.config.js @@ -72,8 +72,10 @@ export default defineConfig(({ mode }) => { changeOrigin: true, secure: true, cookieDomainRewrite: { - "dashboard.kent.pw": "localhost", + "dashboard.kent.pw": "", }, + hostRewrite: true, + autoRewrite: true, configure: (proxy, _options) => { proxy.on("error", (err, req, res) => { console.log("Auth proxy error:", err); @@ -85,13 +87,29 @@ export default defineConfig(({ mode }) => { ); }); proxy.on("proxyReq", (proxyReq, req, _res) => { + proxyReq.setHeader('X-Forwarded-Host', req.headers.host); + proxyReq.setHeader('X-Forwarded-Proto', 'http'); + + const origin = req.headers.origin || `http://${req.headers.host}`; + proxyReq.setHeader('origin', origin); + console.log("Outgoing auth request:", { method: req.method, url: req.url, - headers: req.headers, + headers: proxyReq.getHeaders(), }); }); - proxy.on("proxyRes", (proxyRes, req, _res) => { + proxy.on("proxyRes", (proxyRes, req, res) => { + const cookies = proxyRes.headers['set-cookie']; + if (cookies) { + proxyRes.headers['set-cookie'] = cookies.map(cookie => + cookie + .replace(/Domain=[^;]+;/g, '') + .replace(/Secure;/g, '') + .replace(/SameSite=None/g, 'SameSite=Lax') + ); + } + console.log("Auth proxy response:", { statusCode: proxyRes.statusCode, url: req.url, From cdc0c3cc784ab1b2ab3f1876d32f51d849744bf2 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 23 Dec 2024 23:46:41 -0500 Subject: [PATCH 3/3] Update navigation for new app --- dashboard/src/App.jsx | 16 ++++++++----- .../src/components/dashboard/Navigation.jsx | 24 +++++-------------- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/dashboard/src/App.jsx b/dashboard/src/App.jsx index 9834078..c2b2d8d 100644 --- a/dashboard/src/App.jsx +++ b/dashboard/src/App.jsx @@ -91,27 +91,31 @@ const DashboardLayout = () => {
- +
+ +
-
+
-
+
-
+
-
+
- +
+ +
diff --git a/dashboard/src/components/dashboard/Navigation.jsx b/dashboard/src/components/dashboard/Navigation.jsx index 2e3015f..e5820f8 100644 --- a/dashboard/src/components/dashboard/Navigation.jsx +++ b/dashboard/src/components/dashboard/Navigation.jsx @@ -20,25 +20,13 @@ const Navigation = () => { const baseSections = [ { id: "stats", label: "Statistics" }, { - id: "realtime", - label: "Realtime", - responsiveIds: ["realtime-lg", "realtime-md"], - order: { md: 2, default: 1 }, + id: "feed", + label: "Event Feed", + responsiveIds: ["feed-xl", "feed-lg"], }, - { - id: "products", - label: "Top Products", - responsiveIds: ["products-lg", "products-md"], - order: { md: 1, default: 2 }, - }, - { id: "feed", label: "Activity Feed" }, - { id: "sales", label: "Sales Metrics" }, - { id: "campaigns", label: "Campaigns" }, - { id: "meta", label: "Meta Ads" }, - { id: "analytics", label: "Analytics" }, - { id: "behavior", label: "User Behavior" }, - { id: "gorgias", label: "Customer Service" }, - { id: "calls", label: "Calls" }, + { id: "products", label: "Top Products" }, + { id: "sales", label: "Sales Chart" }, + { id: "calls", label: "Aircall" }, ]; const sortSections = (sections) => {