Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

getWorkspaces → getDefaultWorkspace

Steven Tey8e6ca22b3528
diff --git a/apps/web/app/app.dub.co/(redirects)/analytics/page.tsx b/apps/web/app/app.dub.co/(redirects)/analytics/page.tsx
index c7f13c0774..bf079b6b1e 100644
--- a/apps/web/app/app.dub.co/(redirects)/analytics/page.tsx
+++ b/apps/web/app/app.dub.co/(redirects)/analytics/page.tsx
@@ -1,4 +1,4 @@
-import { getWorkspaces } from "@/lib/fetchers";
+import { getDefaultWorkspace } from "@/lib/fetchers";
import { redirect } from "next/navigation";
export default async function OldLinksAnalytics({
@@ -6,8 +6,8 @@ export default async function OldLinksAnalytics({
}: {
searchParams: { [key: string]: string };
}) {
- const workspaces = await getWorkspaces();
- if (!workspaces || workspaces.length === 0) {
+ const defaultWorkspace = await getDefaultWorkspace();
+ if (!defaultWorkspace) {
redirect("/");
}
@@ -21,6 +21,6 @@ export default async function OldLinksAnalytics({
const queryString = newParams.toString();
redirect(
- `/${workspaces[0].slug}/analytics${queryString ? `?${queryString}` : ""}`,
+ `/${defaultWorkspace.slug}/analytics${queryString ? `?${queryString}` : ""}`,
);
}
diff --git a/apps/web/app/app.dub.co/(redirects)/links/[key]/page.tsx b/apps/web/app/app.dub.co/(redirects)/links/[key]/page.tsx
index 043bd13791..e9cc4f91e8 100644
--- a/apps/web/app/app.dub.co/(redirects)/links/[key]/page.tsx
+++ b/apps/web/app/app.dub.co/(redirects)/links/[key]/page.tsx
@@ -1,4 +1,4 @@
-import { getWorkspaces } from "@/lib/fetchers";
+import { getDefaultWorkspace } from "@/lib/fetchers";
import { redirect } from "next/navigation";
export default async function OldLinksStatsPage({
@@ -8,9 +8,11 @@ export default async function OldLinksStatsPage({
key: string;
};
}) {
- const workspaces = await getWorkspaces();
- if (!workspaces || workspaces.length === 0) {
+ const defaultWorkspace = await getDefaultWorkspace();
+ if (!defaultWorkspace) {
redirect("/");
}
- redirect(`/${workspaces[0].slug}/analytics?domain=dub.sh&key=${params.key}`);
+ redirect(
+ `/${defaultWorkspace.slug}/analytics?domain=dub.sh&key=${params.key}`,
+ );
}
diff --git a/apps/web/app/app.dub.co/(redirects)/links/page.tsx b/apps/web/app/app.dub.co/(redirects)/links/page.tsx
index 6ab4e51114..3a9433e610 100644
--- a/apps/web/app/app.dub.co/(redirects)/links/page.tsx
+++ b/apps/web/app/app.dub.co/(redirects)/links/page.tsx
@@ -1,10 +1,10 @@
-import { getWorkspaces } from "@/lib/fetchers";
+import { getDefaultWorkspace } from "@/lib/fetchers";
import { redirect } from "next/navigation";
export default async function OldLinksPage() {
- const workspaces = await getWorkspaces();
- if (!workspaces || workspaces.length === 0) {
+ const defaultWorkspace = await getDefaultWorkspace();
+ if (!defaultWorkspace) {
redirect("/");
}
- redirect(`/${workspaces[0].slug}`);
+ redirect(`/${defaultWorkspace.slug}`);
}
diff --git a/apps/web/app/app.dub.co/(redirects)/new/page.tsx b/apps/web/app/app.dub.co/(redirects)/new/page.tsx
index dba092a355..05c33201ac 100644
--- a/apps/web/app/app.dub.co/(redirects)/new/page.tsx
+++ b/apps/web/app/app.dub.co/(redirects)/new/page.tsx
@@ -1,10 +1,10 @@
-import { getWorkspaces } from "@/lib/fetchers";
+import { getDefaultWorkspace } from "@/lib/fetchers";
import { redirect } from "next/navigation";
export default async function NewLinkPage() {
- const workspaces = await getWorkspaces();
- if (!workspaces || workspaces.length === 0) {
+ const defaultWorkspace = await getDefaultWorkspace();
+ if (!defaultWorkspace) {
redirect("/?newWorkspace=true");
}
- redirect(`/${workspaces[0].slug}?newLink=true`);
+ redirect(`/${defaultWorkspace.slug}?newLink=true`);
}
diff --git a/apps/web/lib/fetchers.ts b/apps/web/lib/fetchers.ts
index e4757f4226..644019f67c 100644
--- a/apps/web/lib/fetchers.ts
+++ b/apps/web/lib/fetchers.ts
@@ -2,12 +2,12 @@ import { cache } from "react";
import { getSession } from "./auth";
import prisma from "./prisma";
-export const getWorkspaces = cache(async () => {
+export const getDefaultWorkspace = cache(async () => {
const session = await getSession();
if (!session) {
return null;
}
- const workspaces = await prisma.project.findMany({
+ return await prisma.project.findFirst({
where: {
users: {
some: {
@@ -15,13 +15,10 @@ export const getWorkspaces = cache(async () => {
},
},
},
- include: {
- domains: true,
- users: true,
+ select: {
+ slug: true,
},
});
-
- return workspaces;
});
export const getWorkspace = cache(async ({ slug }: { slug: string }) => {