From 3ad6c2de48ef0d19952f3c6895aa44a20efad3f4 Mon Sep 17 00:00:00 2001 From: msukkari Date: Wed, 12 Feb 2025 09:29:00 -0800 Subject: [PATCH] properly block access to pages if user isn't in an org --- packages/web/src/actions.ts | 2 +- packages/web/src/app/components/footer.tsx | 14 ++++ .../src/app/components/noOrganizationCard.tsx | 43 +++++++++++ packages/web/src/app/layout.tsx | 31 +++++++- packages/web/src/app/page.tsx | 9 +-- packages/web/src/app/redeem/page.tsx | 71 +++++++++++++++---- packages/web/src/app/settings/page.tsx | 1 - packages/web/src/auth.ts | 10 +++ packages/web/src/middleware.ts | 20 +++++- 9 files changed, 174 insertions(+), 27 deletions(-) create mode 100644 packages/web/src/app/components/footer.tsx create mode 100644 packages/web/src/app/components/noOrganizationCard.tsx diff --git a/packages/web/src/actions.ts b/packages/web/src/actions.ts index ec5a98e2..89d0d58a 100644 --- a/packages/web/src/actions.ts +++ b/packages/web/src/actions.ts @@ -409,7 +409,7 @@ export async function fetchStripeClientSecret(name: string, domain: string) { ], mode: 'subscription', subscription_data: { - trial_period_days: 14 + trial_period_days: 7, }, customer_email: user.email!, payment_method_collection: 'if_required', diff --git a/packages/web/src/app/components/footer.tsx b/packages/web/src/app/components/footer.tsx new file mode 100644 index 00000000..8f084150 --- /dev/null +++ b/packages/web/src/app/components/footer.tsx @@ -0,0 +1,14 @@ +import Link from "next/link"; +import { Separator } from "@/components/ui/separator"; + +export function Footer() { + return ( + + ) +} \ No newline at end of file diff --git a/packages/web/src/app/components/noOrganizationCard.tsx b/packages/web/src/app/components/noOrganizationCard.tsx new file mode 100644 index 00000000..e13288d8 --- /dev/null +++ b/packages/web/src/app/components/noOrganizationCard.tsx @@ -0,0 +1,43 @@ +"use client" + +import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card" +import { Button } from "@/components/ui/button" +import { useRouter } from "next/navigation" +import { Building2 } from "lucide-react" + +export function NoOrganizationCard() { + const router = useRouter() + + const handleOnboard = () => { + router.push("/onboard") + } + + return ( +
+ + +
+ + No Organization +
+ You're not part of any organization yet. +
+ +

+ Please complete the onboarding process to create an organization. Alternatively, ask your teammate to invite + you to their organization. +

+

+ Something seem wrong? Contact us at team@sourcebot.dev +

+
+ + + +
+
+ ) +} + diff --git a/packages/web/src/app/layout.tsx b/packages/web/src/app/layout.tsx index 44beffe9..886aaa7f 100644 --- a/packages/web/src/app/layout.tsx +++ b/packages/web/src/app/layout.tsx @@ -6,17 +6,46 @@ import { PHProvider } from "./posthogProvider"; import { Toaster } from "@/components/ui/toaster"; import { TooltipProvider } from "@/components/ui/tooltip"; import { SessionProvider } from "next-auth/react"; +import { getCurrentUserOrg } from "@/auth"; +import { isServiceError } from "@/lib/utils"; +import { NavigationMenu } from "./components/navigationMenu"; +import { NoOrganizationCard } from "./components/noOrganizationCard"; +import { Footer } from "./components/footer"; +import { headers } from "next/headers"; export const metadata: Metadata = { title: "Sourcebot", description: "Sourcebot", }; -export default function RootLayout({ +export default async function RootLayout({ children, }: Readonly<{ children: React.ReactNode; }>) { + const orgId = await getCurrentUserOrg(); + const byPassOrgCheck = (await headers()).get("x-bypass-org-check")! == "true"; + if (isServiceError(orgId) && !byPassOrgCheck) { + return ( + + +
+ + + +
+ +
+ ) + + + ) + } + return ( )} - +