diff --git a/apps/browser-extension/package.json b/apps/browser-extension/package.json index 43f3a56ae..0db9933dc 100644 --- a/apps/browser-extension/package.json +++ b/apps/browser-extension/package.json @@ -9,10 +9,9 @@ "dev:firefox": "wxt -b firefox", "build": "wxt build", "build:firefox": "wxt build -b firefox", - "check-types": "bun run compile", + "check-types": "wxt prepare && tsc --noEmit", "zip": "wxt zip", "zip:firefox": "wxt zip -b firefox", - "compile": "tsc --noEmit", "postinstall": "wxt prepare" }, "dependencies": { diff --git a/apps/web/middleware.ts b/apps/web/middleware.ts index 8febfc819..895872271 100644 --- a/apps/web/middleware.ts +++ b/apps/web/middleware.ts @@ -41,13 +41,14 @@ export default async function proxy(request: Request) { return NextResponse.next() } - // MCP setup page is public — no auth required - if (url.searchParams.get("view") === "mcp") { - return NextResponse.next() - } - - // Integrations index is public in guest mode; actions still require login. - if (url.pathname === "/" && url.searchParams.get("view") === "integrations") { + // Integrations index and MCP setup are public in guest mode; actions still + // require login. The ?view param is only meaningful at "/" (see + // lib/view-mode-context, which ignores it elsewhere), so scope it there — + // unscoped, ?view=mcp would let any path skip the /api/ gate below. + if ( + url.pathname === "/" && + ["integrations", "mcp"].includes(url.searchParams.get("view") ?? "") + ) { return NextResponse.next() } diff --git a/packages/ui/other/anonymous-auth.tsx b/packages/ui/other/anonymous-auth.tsx deleted file mode 100644 index 009902f9e..000000000 --- a/packages/ui/other/anonymous-auth.tsx +++ /dev/null @@ -1,150 +0,0 @@ -"use client" - -import { authClient } from "@lib/auth" -import { useRouter } from "next/navigation" -import { useEffect } from "react" - -export const AnonymousAuth = ({ - dashboardPath = "/dashboard", - loginPath = "/login", -}) => { - const router = useRouter() - - useEffect(() => { - const createAnonymousSession = async () => { - const session = await authClient.getSession() - - if (!session?.session) { - console.debug( - "[ANONYMOUS_AUTH] No session found, creating anonymous session...", - ) - - try { - // Create anonymous session - console.debug("[ANONYMOUS_AUTH] Calling signIn.anonymous()...") - const res = await authClient.signIn.anonymous() - - if (!res.token) { - throw new Error("Failed to get anonymous token") - } - - // Get the new session - console.debug( - "[ANONYMOUS_AUTH] Getting new session with anonymous token...", - ) - const newSession = await authClient.getSession() - - console.debug("[ANONYMOUS_AUTH] New session retrieved:", newSession) - - if (!newSession?.session || !newSession?.user) { - console.error( - "[ANONYMOUS_AUTH] Failed to create anonymous session - missing session or user", - ) - throw new Error("Failed to create anonymous session") - } - - // Get the user's organization - console.debug( - "[ANONYMOUS_AUTH] Fetching organizations for anonymous user...", - ) - const orgs = await authClient.organization.list() - - console.debug("[ANONYMOUS_AUTH] Organizations retrieved:", { - count: orgs?.length || 0, - orgs: orgs?.map((o) => ({ - id: o.id, - name: o.name, - slug: o.slug, - })), - }) - - const org = orgs?.[0] - if (!org) { - console.error( - "[ANONYMOUS_AUTH] No organization found for anonymous user", - ) - throw new Error("Failed to get organization for anonymous user") - } - - // Redirect to the organization dashboard - console.debug( - `[ANONYMOUS_AUTH] Redirecting anonymous user to /${org.slug}${dashboardPath}`, - ) - router.push(dashboardPath) - } catch (error) { - console.error( - "[ANONYMOUS_AUTH] Anonymous session creation error:", - error, - ) - console.error("[ANONYMOUS_AUTH] Error details:", { - message: error instanceof Error ? error.message : "Unknown error", - stack: error instanceof Error ? error.stack : undefined, - }) - router.push(loginPath) - } - } else if (session.session) { - // Session exists, handle organization routing - console.debug( - "[ANONYMOUS_AUTH] Session exists, checking organization...", - ) - - if (!session.session.activeOrganizationId) { - console.debug( - "[ANONYMOUS_AUTH] No active organization ID, fetching organizations...", - ) - const orgs = await authClient.organization.list() - - console.debug("[ANONYMOUS_AUTH] Organizations for existing user:", { - count: orgs?.length || 0, - orgs: orgs?.map((o) => ({ - id: o.id, - name: o.name, - slug: o.slug, - })), - }) - - if (orgs?.[0]) { - console.debug( - `[ANONYMOUS_AUTH] Setting active organization to ${orgs[0].id}`, - ) - await authClient.organization.setActive({ - organizationId: orgs[0].id, - }) - console.debug( - `[ANONYMOUS_AUTH] Redirecting to /${orgs[0].slug}${dashboardPath}`, - ) - router.push(dashboardPath) - } - } else { - console.debug( - `[ANONYMOUS_AUTH] Active organization ID: ${session.session.activeOrganizationId}`, - ) - console.debug( - "[ANONYMOUS_AUTH] Fetching full organization details...", - ) - const org = await authClient.organization.getFullOrganization({ - query: { - organizationId: session.session.activeOrganizationId, - }, - }) - - console.debug("[ANONYMOUS_AUTH] Full organization retrieved:", { - id: org.id, - name: org.name, - slug: org.slug, - }) - - console.debug( - `[ANONYMOUS_AUTH] Redirecting to /${org.slug}${dashboardPath}`, - ) - router.push(dashboardPath) - } - } - } - - createAnonymousSession() - }, [router.push]) - - // Return null as this component only handles the redirect logic - return null -}