From 75c8216bac3d2054f36e535b180fe199351cbaab Mon Sep 17 00:00:00 2001 From: Prashantkumar Khatri <96608160+ShantKhatri@users.noreply.github.com> Date: Thu, 28 May 2026 14:19:42 +0530 Subject: [PATCH] Revert "build analytics dashboard page at /devcard/analytics (#73)" This reverts commit 31bdf09048bc28a6edcb9529a2e5d12a17ffa4ad. --- apps/backend/src/app.ts | 10 - apps/backend/src/routes/auth.ts | 24 - apps/backend/src/routes/connect.ts | 2 +- apps/web/postcss.config.js | 5 - .../routes/devcard/analytics/+page.server.ts | 89 --- .../src/routes/devcard/analytics/+page.svelte | 749 ------------------ 6 files changed, 1 insertion(+), 878 deletions(-) delete mode 100644 apps/web/postcss.config.js delete mode 100644 apps/web/src/routes/devcard/analytics/+page.server.ts delete mode 100644 apps/web/src/routes/devcard/analytics/+page.svelte diff --git a/apps/backend/src/app.ts b/apps/backend/src/app.ts index f3f6b7a3..9fc750a0 100644 --- a/apps/backend/src/app.ts +++ b/apps/backend/src/app.ts @@ -10,13 +10,6 @@ import rateLimit from '@fastify/rate-limit'; import fastifyStatic from '@fastify/static'; import Fastify, {type FastifyInstance} from 'fastify'; -declare module 'fastify' { - interface FastifyInstance { - authenticate: any; - } -} - - import { prismaPlugin } from './plugins/prisma.js'; import { redisPlugin } from './plugins/redis.js'; import { analyticsRoutes } from './routes/analytics.js'; @@ -96,9 +89,6 @@ export async function buildApp():Promise { // ─── Auth Decorator ─── app.decorate('authenticate', async function (request: any, reply: any) { try { - if (!request.headers.authorization && request.cookies && request.cookies.token) { - request.headers.authorization = `Bearer ${request.cookies.token}`; - } await request.jwtVerify(); } catch (_err) { reply.status(401).send({ error: 'Unauthorized' }); diff --git a/apps/backend/src/routes/auth.ts b/apps/backend/src/routes/auth.ts index 836f6323..fc90f2ec 100644 --- a/apps/backend/src/routes/auth.ts +++ b/apps/backend/src/routes/auth.ts @@ -351,30 +351,6 @@ app.get('/github/callback', async (request: FastifyRequest<{ Querystring: OAuthC reply.clearCookie('token', { path: '/' }); return { message: 'Logged out' }; }); - - // ─── Dev Login Bypass ─── - if (process.env.NODE_ENV !== 'production') { - app.get('/dev-login', async (request: FastifyRequest, reply: FastifyReply) => { - const user = await app.prisma.user.findUnique({ - where: { username: 'devcard-demo' }, - }); - if (!user) { - return reply.status(404).send({ error: 'Demo user not found' }); - } - const token = app.jwt.sign( - { id: user.id, username: user.username }, - { expiresIn: '30d' } - ); - reply.setCookie('token', token, { - httpOnly: true, - secure: false, - sameSite: 'lax', - path: '/', - maxAge: 30 * 24 * 60 * 60, - }); - return reply.redirect(`${process.env.PUBLIC_APP_URL || 'http://localhost:5173'}/devcard/analytics`); - }); - } } function generateState(): string { diff --git a/apps/backend/src/routes/connect.ts b/apps/backend/src/routes/connect.ts index 487694f3..02f6dce3 100644 --- a/apps/backend/src/routes/connect.ts +++ b/apps/backend/src/routes/connect.ts @@ -107,7 +107,7 @@ app.get('/github', { const tokenData = (await tokenRes.json()) as any; if (tokenData.error) { - app.log.error(tokenData, 'GitHub connect token error'); + app.log.error('GitHub connect token error:', tokenData); return reply.redirect(`${process.env.PUBLIC_APP_URL}/settings?error=connect_failed`); } diff --git a/apps/web/postcss.config.js b/apps/web/postcss.config.js deleted file mode 100644 index 8c0f51be..00000000 --- a/apps/web/postcss.config.js +++ /dev/null @@ -1,5 +0,0 @@ -export default { - plugins: { - autoprefixer: {} - } -}; diff --git a/apps/web/src/routes/devcard/analytics/+page.server.ts b/apps/web/src/routes/devcard/analytics/+page.server.ts deleted file mode 100644 index 8898e1b2..00000000 --- a/apps/web/src/routes/devcard/analytics/+page.server.ts +++ /dev/null @@ -1,89 +0,0 @@ -import type { PageServerLoad } from './$types'; -import { redirect } from '@sveltejs/kit'; -import { dev } from '$app/environment'; - -const API_BASE = process.env.BACKEND_URL || 'http://localhost:3000'; - -export interface AnalyticsOverview { - totalViews: number; - viewsToday: number; - uniqueViewers: number; - totalFollows: number; - recentViews: Array<{ - createdAt: string; - source: string; - viewer?: { - avatarUrl?: string; - displayName?: string; - }; - }>; -} - -export interface AnalyticsViews { - meta: { - total: number; - }; - data: Array<{ - createdAt: string; - source: string; - viewerIp?: string; - viewer?: { - displayName?: string; - username?: string; - }; - card?: { - title?: string; - }; - }>; -} - -export const load: PageServerLoad = async ({ fetch, cookies }) => { - const token = cookies.get('token'); - - if (!token) { - if (!dev) { - throw redirect(302, '/'); - } - return { - overview: null, - views: null, - error: 'Please log in to view analytics' - }; - } - - try { - const headers = { Authorization: `Bearer ${token}` }; - const [overviewRes, viewsRes] = await Promise.all([ - fetch(`${API_BASE}/api/analytics/overview`, { headers }), - fetch(`${API_BASE}/api/analytics/views`, { headers }) - ]); - - if (!overviewRes.ok || !viewsRes.ok) { - if (overviewRes.status === 401 || viewsRes.status === 401) { - if (!dev) { - throw redirect(302, '/'); - } - } - return { - overview: null, - views: null, - error: 'Please log in to view analytics' - }; - } - - const overview = (await overviewRes.json()) as AnalyticsOverview; - const views = (await viewsRes.json()) as AnalyticsViews; - - return { overview, views, error: null }; - } catch (err) { - // If it's a redirect thrown by SvelteKit, let it bubble up - if (err && typeof err === 'object' && 'status' in err && 'location' in err) { - throw err; - } - return { - overview: null, - views: null, - error: 'Analytics service unavailable' - }; - } -}; diff --git a/apps/web/src/routes/devcard/analytics/+page.svelte b/apps/web/src/routes/devcard/analytics/+page.svelte deleted file mode 100644 index f5308458..00000000 --- a/apps/web/src/routes/devcard/analytics/+page.svelte +++ /dev/null @@ -1,749 +0,0 @@ - - - - Analytics Dashboard — DevCard - - -
-
-
-

Analytics Dashboard

-

Track your DevCard performance and reach.

-
- -
- - {#if error} -
-
🔒
-

{error}

-

Accessing the dashboard requires an active session.

-
- Return Home - {#if dev} - Dev Login Bypass - {/if} -
-
- {:else if overview} - -
-
- Total Views -
{overview.totalViews}
- -
-
- Views Today -
{overview.viewsToday}
- -
-
- Unique Viewers -
{overview.uniqueViewers}
- -
-
- Total Follows -
{overview.totalFollows}
- -
-
- - -
-
-
-

Daily Views (Last 7 Days)

- Interactive -
-
- {#if dailyViewsData.length > 0} - - - - - - - - - - - - - - - {#if areaPath} - - {/if} - - - {#if linePath} - - {/if} - - - {#each chartPoints as pt} - - - - {pt.count} - - - {/each} - - - {#each chartPoints as pt} - - {pt.label} - - {/each} - - {:else} -
No view statistics available yet.
- {/if} -
-
- -
-
-

Platform Click Rankings

- Real-time -
-
- {#each platformClicks as item, index} -
-
- - #{index + 1} {item.platform} - - {item.count} clicks -
-
-
-
-
- {/each} - {#if platformClicks.length === 0} -

No platform click details available yet.

- {/if} -
-
-
- -
- -
-

Recent Activity

-
- {#each overview.recentViews as view} -
-
- {#if isValidAvatar(view.viewer?.avatarUrl)} - - {:else} -
{view.viewer?.displayName?.charAt(0) || '?'}
- {/if} -
-
- {view.viewer?.displayName || 'Anonymous User'} - viewed via {view.source} -
-
{formatDate(view.createdAt)}
-
- {/each} - {#if overview.recentViews.length === 0} -

No recent activity found.

- {/if} -
-
- - -
-
-
-

Detailed View Logs

- {views?.meta?.total || 0} Total -
- -
-
- - - - - - - - - - - - {#each views?.data || [] as view} - - - - - - - - {/each} - -
ViewerCardSourceIP AddressDate
-
- {view.viewer?.displayName || 'Guest'} - {#if view.viewer?.username} - @{view.viewer.username} - {/if} -
-
{view.card?.title || 'Profile'}{view.source}{view.viewerIp || '—'}{formatDate(view.createdAt)}
- {#if !views?.data?.length} -
No detailed logs available yet.
- {/if} -
-
-
- {/if} -
- -