Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eng 1343 workos #2692

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type PageProps = {
};

async function AsyncPageBreadcrumb(props: PageProps) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const getApiById = cache(
async (apiId: string) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type PageProps = {
};

async function AsyncPageBreadcrumb(props: PageProps) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const getApiById = cache(
async (apiId: string) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type PageProps = {
};

async function AsyncPageBreadcrumb(props: PageProps) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const getApiById = cache(
async (apiId: string) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type PageProps = {
};

async function AsyncPageBreadcrumb(props: PageProps) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const getApiById = cache(
async (apiId: string) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { BreadcrumbSkeleton } from "@/components/dashboard/breadcrumb-skeleton";
import { getTenantId } from "@/lib/auth";
import { db } from "@/lib/db";
import { Suspense } from "react";
import { redirect } from "next/navigation";

export const dynamic = "force-dynamic";
export const runtime = "edge";
Expand All @@ -21,7 +22,7 @@ type PageProps = {
};

async function AsyncPageBreadcrumb(props: PageProps) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const getApiById = cache(
async (apiId: string) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const runtime = "edge";
type PageProps = { params: { apiId: string } };

async function AsyncPageBreadcrumb(props: PageProps) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const getApiById = cache(
async (apiId: string) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type PageProps = {
};

async function AsyncPageBreadcrumb(props: PageProps) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const getIdentityById = cache(
async (identityId: string) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default async function APIKeyDetailPage(props: {
interval?: Interval;
};
}) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const key = await db.query.keys.findFirst({
where: and(eq(schema.keys.id, props.params.keyId), isNull(schema.keys.deletedAt)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Props = {
};

export default async function SettingsPage(props: Props) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const key = await db.query.keys.findFirst({
where: and(eq(schema.keys.id, props.params.keyId), isNull(schema.keys.deletedAt)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default async function CreateKeypage(props: {
keyAuthId: string;
};
}) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const keyAuth = await db.query.keyAuth.findFirst({
where: (table, { eq, and, isNull }) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default async function APIKeysPage(props: {
keyAuthId: string;
};
}) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const keyAuth = await db.query.keyAuth.findFirst({
where: (table, { eq, and, isNull }) =>
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/(app)/apis/[apiId]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const dynamic = "force-dynamic";
export const runtime = "edge";

export default async function ApiPageLayout(props: Props) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const api = await db.query.apis.findFirst({
where: (table, { eq, and, isNull }) =>
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/(app)/apis/[apiId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default async function ApiPage(props: {
interval?: Interval;
};
}) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const api = await db.query.apis.findFirst({
where: (table, { eq, and, isNull }) =>
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/(app)/apis/[apiId]/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Props = {
};

export default async function SettingsPage(props: Props) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const workspace = await db.query.workspaces.findFirst({
where: (table, { and, eq, isNull }) =>
Expand Down
6 changes: 3 additions & 3 deletions apps/dashboard/app/(app)/apis/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Button } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Separator } from "@/components/ui/separator";
import { PostHogIdentify } from "@/providers/PostHogProvider";
import { useUser } from "@clerk/nextjs";
import { useUser } from "@/lib/auth/hooks/useUser";
import { BookOpen, Code, Search } from "lucide-react";
import Link from "next/link";
import { useEffect, useState } from "react";
Expand All @@ -19,14 +19,14 @@ type ApiWithKeys = {
}[];

export function ApiList({ apis }: { apis: ApiWithKeys }) {
const { user, isLoaded } = useUser();
const { user, isLoading } = useUser();
useEffect(() => {
if (apis.length) {
setLocalData(apis);
}
}, [apis]);
const [localData, setLocalData] = useState(apis);
if (isLoaded && user) {
if (!isLoading && user) {
PostHogIdentify({ user });
}
return (
Expand Down
7 changes: 6 additions & 1 deletion apps/dashboard/app/(app)/apis/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export const dynamic = "force-dynamic";
export const runtime = "edge";

export default async function ApisOverviewPage() {
const tenantId = getTenantId();
const tenantId = await getTenantId();
console.log("Api Page", tenantId);

const workspace = await db.query.workspaces.findFirst({
where: (table, { and, eq, isNull }) =>
and(eq(table.tenantId, tenantId), isNull(table.deletedAt)),
Expand All @@ -24,7 +26,10 @@ export default async function ApisOverviewPage() {
},
});

console.log("api workspace check", workspace);

if (!workspace) {
console.log("no workspace, redirecting to new")
return redirect("/new");
}

Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/(app)/audit/[bucket]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Props = {
const filterParser = parseAsArrayOf(parseAsString).withDefault([]);

export default async function AuditPage(props: Props) {
const tenantId = getTenantId();
const tenantId = await getTenantId();
const workspace = await db.query.workspaces.findFirst({
where: (table, { eq, and, isNull }) =>
and(eq(table.tenantId, tenantId), isNull(table.deletedAt)),
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/(app)/authorization/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default async function AuthorizationLayout({
}: {
children: React.ReactNode;
}) {
const tenantId = getTenantId();
const tenantId = await getTenantId();
const workspace = await db.query.workspaces.findFirst({
where: (table, { eq }) => eq(table.tenantId, tenantId),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Props = {
};

export default async function RolesPage(props: Props) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const workspace = await db.query.workspaces.findFirst({
where: (table, { eq }) => eq(table.tenantId, tenantId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { CreateNewPermission } from "./create-new-permission";
export const revalidate = 0;

export default async function RolesPage() {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const workspace = await db.query.workspaces.findFirst({
where: (table, { and, eq, isNull }) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Props = {
};

export default async function RolesPage(props: Props) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const workspace = await db.query.workspaces.findFirst({
where: (table, { eq }) => eq(table.tenantId, tenantId),
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/(app)/authorization/roles/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { CreateNewRole } from "./create-new-role";
export const revalidate = 0;

export default async function RolesPage() {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const workspace = await db.query.workspaces.findFirst({
where: (table, { and, eq, isNull }) =>
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/(app)/debug/ws/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { db } from "@/lib/db";
export const revalidate = 0;

export default async function DebugWorkspacePage() {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const workspace = await db.query.workspaces.findFirst({
where: (table, { and, eq, isNull }) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Props = {
};

export default async function Page(props: Props) {
const tenantId = getTenantId();
const tenantId = await getTenantId();
const identity = await db.query.identities.findFirst({
where: (table, { eq }) => eq(table.id, props.params.identityId),
with: {
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/(app)/identities/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default async function AuthorizationLayout({
}: {
children: React.ReactNode;
}) {
const tenantId = getTenantId();
const tenantId = await getTenantId();
const workspace = await db.query.workspaces.findFirst({
where: (table, { eq }) => eq(table.tenantId, tenantId),
});
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/(app)/identities/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default async function Page(props: Props) {
}

const Results: React.FC<{ search: string; limit: number }> = async (props) => {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const getData = cache(
async () =>
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/app/(app)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface LayoutProps {
}

export default async function Layout({ children, breadcrumb }: LayoutProps) {
const tenantId = getTenantId();
const tenantId = await getTenantId();
const workspace = await db.query.workspaces.findFirst({
where: (table, { and, eq, isNull }) =>
and(eq(table.tenantId, tenantId), isNull(table.deletedAt)),
Expand All @@ -25,7 +25,7 @@ export default async function Layout({ children, breadcrumb }: LayoutProps) {
},
});
if (!workspace) {
return redirect("/apis");
return redirect("/new");
}

return (
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/(app)/logs/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { db } from "@/lib/db";
export const revalidate = 0;

export default async function Page() {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const workspace = await db.query.workspaces.findFirst({
where: (table, { and, eq, isNull }) =>
Expand Down
3 changes: 2 additions & 1 deletion apps/dashboard/app/(app)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { db } from "@/lib/db";
import { redirect } from "next/navigation";

export default async function TenantOverviewPage() {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const workspace = await db.query.workspaces.findFirst({
where: (table, { and, eq, isNull }) =>
and(eq(table.tenantId, tenantId), isNull(table.deletedAt)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const dynamic = "force-dynamic";
export const runtime = "edge";

export default async function RatelimitNamespacePageLayout(props: Props) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const namespace = await db.query.ratelimitNamespaces.findFirst({
where: (table, { eq, and, isNull }) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type Props = {
const stringParser = parseAsArrayOf(parseAsString).withDefault([]);

export default async function AuditPage(props: Props) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const namespace = await db.query.ratelimitNamespaces.findFirst({
where: (table, { eq, and, isNull }) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Props = {
};

export default async function OverrideSettings(props: Props) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const override = await db.query.ratelimitOverrides.findFirst({
where: (table, { and, eq, isNull }) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Props = {
};

export default async function OverridePage(props: Props) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const namespace = await db.query.ratelimitNamespaces.findFirst({
where: (table, { eq, and, isNull }) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default async function RatelimitNamespacePage(props: {
identifier?: string;
};
}) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const namespace = await db.query.ratelimitNamespaces.findFirst({
where: (table, { eq, and, isNull }) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Props = {
};

export default async function SettingsPage(props: Props) {
const tenantId = getTenantId();
const tenantId = await getTenantId();

const workspace = await db.query.workspaces.findFirst({
where: (table, { and, eq, isNull }) =>
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/(app)/ratelimits/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const dynamic = "force-dynamic";
export const runtime = "edge";

export default async function RatelimitOverviewPage() {
const tenantId = getTenantId();
const tenantId = await getTenantId();
const workspace = await db.query.workspaces.findFirst({
where: (table, { and, eq, isNull }) =>
and(eq(table.tenantId, tenantId), isNull(table.deletedAt)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default async function SemanticCacheAnalyticsPage(props: {
}) {
const interval = props.searchParams.interval ?? "24h";

const tenantId = getTenantId();
const tenantId = await getTenantId();
const workspace = await db.query.workspaces.findFirst({
where: (table, { and, eq, isNull }) =>
and(eq(table.tenantId, tenantId), isNull(table.deletedAt)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getInterval } from "./util";
export default async function SemanticCacheLogsPage({
searchParams,
}: { searchParams: { interval?: string } }) {
const tenantId = getTenantId();
const tenantId = await getTenantId();
const workspace = await db.query.workspaces.findFirst({
where: (table, { and, eq, isNull }) =>
and(eq(table.tenantId, tenantId), isNull(table.deletedAt)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { redirect } from "next/navigation";
import { DeleteGateway } from "./delete-gateway";

export default async function SemanticCacheSettingPage() {
const tenantId = getTenantId();
const tenantId = await getTenantId();
const workspace = await db.query.workspaces.findFirst({
where: (table, { and, eq, isNull }) =>
and(eq(table.tenantId, tenantId), isNull(table.deletedAt)),
Expand Down
Loading
Loading