From 9897c725de27d0fa24066e13756b032a30aefa3b Mon Sep 17 00:00:00 2001 From: Mike Cao Date: Mon, 22 Sep 2025 13:09:07 -0700 Subject: [PATCH] Updated cloud mode checks. --- next.config.ts | 12 +---- pnpm-lock.yaml | 48 +------------------ src/app/(main)/UpdateNotice.tsx | 2 +- src/app/(main)/admin/AdminLayout.tsx | 2 +- src/app/(main)/admin/layout.tsx | 2 +- src/app/(main)/links/LinkEditForm.tsx | 4 +- src/app/(main)/settings/layout.tsx | 2 +- .../[websiteId]/cohorts/CohortEditForm.tsx | 5 +- src/app/api/config/route.ts | 3 +- src/app/login/page.tsx | 2 +- src/app/logout/page.tsx | 4 +- src/components/hooks/useConfig.ts | 1 - src/components/input/ProfileButton.tsx | 5 +- src/components/input/SettingsButton.tsx | 4 +- src/components/messages.ts | 2 +- src/lib/auth.ts | 6 +-- 16 files changed, 23 insertions(+), 81 deletions(-) diff --git a/next.config.ts b/next.config.ts index 40c94fa2..eac6f327 100644 --- a/next.config.ts +++ b/next.config.ts @@ -5,7 +5,7 @@ const TRACKER_SCRIPT = '/script.js'; const basePath = process.env.BASE_PATH; const collectApiEndpoint = process.env.COLLECT_API_ENDPOINT; -const cloudUrl = process.env.CLOUD_URL; +const cloudMode = !!process.env.CLOUD_MODE; const corsMaxAge = process.env.CORS_MAX_AGE; const defaultLocale = process.env.DEFAULT_LOCALE; const forceSSL = process.env.FORCE_SSL; @@ -157,20 +157,12 @@ if (trackerScriptName) { } } -if (cloudUrl) { - redirects.push({ - source: '/login', - destination: cloudUrl, - permanent: false, - }); -} - /** @type {import('next').NextConfig} */ export default { reactStrictMode: false, env: { basePath, - cloudUrl, + cloudMode, currentVersion: pkg.version, defaultLocale, }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cc1199ff..865d02cf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -364,44 +364,7 @@ importers: specifier: ^5.9.2 version: 5.9.2 - dist: - dependencies: - chart.js: - specifier: ^4.5.0 - version: 4.5.0 - chartjs-adapter-date-fns: - specifier: ^3.0.0 - version: 3.0.0(chart.js@4.5.0)(date-fns@2.30.0) - colord: - specifier: ^2.9.2 - version: 2.9.3 - jsonwebtoken: - specifier: ^9.0.2 - version: 9.0.2 - lucide-react: - specifier: ^0.542.0 - version: 0.542.0(react@19.1.1) - pure-rand: - specifier: ^7.0.1 - version: 7.0.1 - react-simple-maps: - specifier: ^2.3.0 - version: 2.3.0(prop-types@15.8.1)(react-dom@19.1.1(react@19.1.1))(react@19.1.1) - react-use-measure: - specifier: ^2.0.4 - version: 2.1.7(react-dom@19.1.1(react@19.1.1))(react@19.1.1) - react-window: - specifier: ^1.8.6 - version: 1.8.11(react-dom@19.1.1(react@19.1.1))(react@19.1.1) - serialize-error: - specifier: ^12.0.0 - version: 12.0.0 - thenby: - specifier: ^1.3.4 - version: 1.3.4 - uuid: - specifier: ^11.1.0 - version: 11.1.0 + dist: {} packages: @@ -5274,11 +5237,6 @@ packages: peerDependencies: react: ^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0 - lucide-react@0.542.0: - resolution: {integrity: sha512-w3hD8/SQB7+lzU2r4VdFyzzOzKnUjTZIF/MQJGSSvni7Llewni4vuViRppfRAa2guOsY5k4jZyxw/i9DQHv+dw==} - peerDependencies: - react: ^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0 - lucide-react@0.543.0: resolution: {integrity: sha512-fpVfuOQO0V3HBaOA1stIiP/A2fPCXHIleRZL16Mx3HmjTYwNSbimhnFBygs2CAfU1geexMX5ItUcWBGUaqw5CA==} peerDependencies: @@ -13394,10 +13352,6 @@ snapshots: dependencies: react: 19.1.1 - lucide-react@0.542.0(react@19.1.1): - dependencies: - react: 19.1.1 - lucide-react@0.543.0(react@19.1.1): dependencies: react: 19.1.1 diff --git a/src/app/(main)/UpdateNotice.tsx b/src/app/(main)/UpdateNotice.tsx index c971d403..35728791 100644 --- a/src/app/(main)/UpdateNotice.tsx +++ b/src/app/(main)/UpdateNotice.tsx @@ -18,7 +18,7 @@ export function UpdateNotice({ user, config }) { !config?.updatesDisabled && !config?.privateMode && !pathname.includes('/share/') && - !process.env.cloudUrl && + !process.env.cloudMode && !dismissed; const updateCheck = useCallback(() => { diff --git a/src/app/(main)/admin/AdminLayout.tsx b/src/app/(main)/admin/AdminLayout.tsx index eb4c2ffa..8b138785 100644 --- a/src/app/(main)/admin/AdminLayout.tsx +++ b/src/app/(main)/admin/AdminLayout.tsx @@ -11,7 +11,7 @@ export function AdminLayout({ children }: { children: ReactNode }) { const { formatMessage, labels } = useMessages(); const { pathname } = useNavigation(); - if (!user.isAdmin || process.env.cloudUrl) { + if (!user.isAdmin || process.env.cloudMode) { return null; } diff --git a/src/app/(main)/admin/layout.tsx b/src/app/(main)/admin/layout.tsx index 3dea4142..634fc658 100644 --- a/src/app/(main)/admin/layout.tsx +++ b/src/app/(main)/admin/layout.tsx @@ -2,7 +2,7 @@ import { Metadata } from 'next'; import { AdminLayout } from './AdminLayout'; export default function ({ children }) { - if (process.env.cloudUrl) { + if (process.env.cloudMode) { return null; } diff --git a/src/app/(main)/links/LinkEditForm.tsx b/src/app/(main)/links/LinkEditForm.tsx index 16c65aec..23aaab1e 100644 --- a/src/app/(main)/links/LinkEditForm.tsx +++ b/src/app/(main)/links/LinkEditForm.tsx @@ -139,7 +139,9 @@ export function LinkEditForm({ {formatMessage(labels.cancel)} )} - {formatMessage(labels.save)} + + {formatMessage(labels.save)} + ); diff --git a/src/app/(main)/settings/layout.tsx b/src/app/(main)/settings/layout.tsx index 6f409e48..fcc7392a 100644 --- a/src/app/(main)/settings/layout.tsx +++ b/src/app/(main)/settings/layout.tsx @@ -2,7 +2,7 @@ import { Metadata } from 'next'; import { SettingsLayout } from './SettingsLayout'; export default function ({ children }) { - if (process.env.cloudUrl) { + if (process.env.cloudMode) { return null; } diff --git a/src/app/(main)/websites/[websiteId]/cohorts/CohortEditForm.tsx b/src/app/(main)/websites/[websiteId]/cohorts/CohortEditForm.tsx index cfe55230..c02d85c9 100644 --- a/src/app/(main)/websites/[websiteId]/cohorts/CohortEditForm.tsx +++ b/src/app/(main)/websites/[websiteId]/cohorts/CohortEditForm.tsx @@ -114,10 +114,7 @@ export function CohortEditForm({ - + diff --git a/src/app/api/config/route.ts b/src/app/api/config/route.ts index 7fa9ce8e..4e40caa4 100644 --- a/src/app/api/config/route.ts +++ b/src/app/api/config/route.ts @@ -9,8 +9,7 @@ export async function GET(request: Request) { } return json({ - cloudMode: !!process.env.CLOUD_URL, - cloudUrl: process.env.CLOUD_URL, + cloudMode: !!process.env.CLOUD_MODE, faviconUrl: process.env.FAVICON_URL, linksUrl: process.env.LINKS_URL, pixelsUrl: process.env.PIXELS_URL, diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index 4c8d8044..8abf7a4e 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -2,7 +2,7 @@ import { Metadata } from 'next'; import { LoginPage } from './LoginPage'; export default async function () { - if (process.env.DISABLE_LOGIN) { + if (process.env.DISABLE_LOGIN || process.env.CLOUD_MODE) { return null; } diff --git a/src/app/logout/page.tsx b/src/app/logout/page.tsx index 7b56ea67..0617c2e2 100644 --- a/src/app/logout/page.tsx +++ b/src/app/logout/page.tsx @@ -1,8 +1,8 @@ -import { LogoutPage } from './LogoutPage'; import { Metadata } from 'next'; +import { LogoutPage } from './LogoutPage'; export default function () { - if (process.env.DISABLE_LOGIN) { + if (process.env.DISABLE_LOGIN || process.env.CLOUD_MODE) { return null; } diff --git a/src/components/hooks/useConfig.ts b/src/components/hooks/useConfig.ts index 17013643..643b9cbc 100644 --- a/src/components/hooks/useConfig.ts +++ b/src/components/hooks/useConfig.ts @@ -4,7 +4,6 @@ import { useApi } from '@/components/hooks/useApi'; export type Config = { cloudMode: boolean; - cloudUrl?: string; faviconUrl?: string; linksUrl?: string; pixelsUrl?: string; diff --git a/src/components/input/ProfileButton.tsx b/src/components/input/ProfileButton.tsx index 017ea831..03f14d07 100644 --- a/src/components/input/ProfileButton.tsx +++ b/src/components/input/ProfileButton.tsx @@ -11,14 +11,13 @@ import { Text, Row, } from '@umami/react-zen'; -import { useMessages, useLoginQuery, useNavigation, useConfig } from '@/components/hooks'; +import { useMessages, useLoginQuery, useNavigation } from '@/components/hooks'; import { LogOut, UserCircle, LockKeyhole } from '@/components/icons'; export function ProfileButton() { const { formatMessage, labels } = useMessages(); const { user } = useLoginQuery(); const { renderUrl } = useNavigation(); - const { cloudUrl } = useConfig(); const items = [ { @@ -28,7 +27,7 @@ export function ProfileButton() { icon: , }, user.isAdmin && - !cloudUrl && { + !process.env.cloudMode && { id: 'admin', label: formatMessage(labels.admin), path: '/admin', diff --git a/src/components/input/SettingsButton.tsx b/src/components/input/SettingsButton.tsx index 7e5ac485..68fd2cdc 100644 --- a/src/components/input/SettingsButton.tsx +++ b/src/components/input/SettingsButton.tsx @@ -16,12 +16,12 @@ export function SettingsButton() { const { formatMessage, labels } = useMessages(); const { user } = useLoginQuery(); const { router, renderUrl } = useNavigation(); - const { cloudMode, cloudUrl } = useConfig(); + const { cloudMode } = useConfig(); const handleAction = (id: Key) => { if (id === 'settings') { if (cloudMode) { - window.location.href = `${cloudUrl}/settings`; + window.location.href = `/settings`; return; } } diff --git a/src/components/messages.ts b/src/components/messages.ts index ebd8c765..1abe98f2 100644 --- a/src/components/messages.ts +++ b/src/components/messages.ts @@ -359,7 +359,7 @@ export const labels = defineMessages({ invalidUrl: { id: 'label.invalid-url', defaultMessage: 'Invalid URL' }, environment: { id: 'label.environment', defaultMessage: 'Environment' }, criteria: { id: 'label.criteria', defaultMessage: 'Criteria' }, - share: { defaultMessage: 'label.share', id: 'Share' }, + share: { id: 'label.share', defaultMessage: 'Share' }, }); export const messages = defineMessages({ diff --git a/src/lib/auth.ts b/src/lib/auth.ts index 46af18b8..80fda55c 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -18,7 +18,7 @@ export function getBearerToken(request: Request) { export async function checkAuth(request: Request) { const token = getBearerToken(request); const payload = parseSecureToken(token, secret()); - const shareToken = await parseShareToken(request.headers); + const shareToken = await parseShareToken(request); let user = null; const { userId, authKey, grant } = payload || {}; @@ -71,9 +71,9 @@ export async function hasPermission(role: string, permission: string | string[]) return ensureArray(permission).some(e => ROLE_PERMISSIONS[role]?.includes(e)); } -export function parseShareToken(headers: Headers) { +export function parseShareToken(request: Request) { try { - return parseToken(headers.get(SHARE_TOKEN_HEADER), secret()); + return parseToken(request.headers.get(SHARE_TOKEN_HEADER), secret()); } catch (e) { log(e); return null;