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.

redirect to `/workspaces` if no workspaces

Steven Tey734171376c99
diff --git a/apps/web/lib/middleware/app.ts b/apps/web/lib/middleware/app.ts
index 6298f5ac4a..c97cf762c2 100644
--- a/apps/web/lib/middleware/app.ts
+++ b/apps/web/lib/middleware/app.ts
@@ -34,7 +34,7 @@ export default async function AppMiddleware(req: NextRequest) {
user.createdAt &&
new Date(user.createdAt).getTime() > Date.now() - 10000 &&
// here we include the root page + /new (since they're going through welcome flow already)
- path === "/"
+ path !== "/welcome"
) {
return NextResponse.redirect(new URL("/welcome", req.url));
@@ -42,12 +42,14 @@ export default async function AppMiddleware(req: NextRequest) {
} else if (path === "/" || path === "/login" || path === "/register") {
const defaultWorkspace = await getDefaultWorkspace(user);
- return NextResponse.redirect(new URL(`/${defaultWorkspace}`, req.url));
+ if (defaultWorkspace) {
+ return NextResponse.redirect(new URL(`/${defaultWorkspace}`, req.url));
+ } else {
+ return NextResponse.redirect(new URL("/workspaces", req.url));
+ }
}
}
// otherwise, rewrite the path to /app
- return NextResponse.rewrite(
- new URL(`/app.dub.co${fullPath === "/" ? "" : fullPath}`, req.url),
- );
+ return NextResponse.rewrite(new URL(`/app.dub.co${fullPath}`, req.url));
}
diff --git a/apps/web/lib/middleware/new-link.ts b/apps/web/lib/middleware/new-link.ts
index 194aeddaee..0d71c8fbfd 100644
--- a/apps/web/lib/middleware/new-link.ts
+++ b/apps/web/lib/middleware/new-link.ts
@@ -22,6 +22,8 @@ export default async function NewLinkMiddleware(
),
);
} else {
- return NextResponse.redirect(new URL(`/?newWorkspace=true`, req.url));
+ return NextResponse.redirect(
+ new URL(`/workspaces?newWorkspace=true`, req.url),
+ );
}
}
diff --git a/apps/web/ui/layout/workspace-switcher.tsx b/apps/web/ui/layout/workspace-switcher.tsx
index d827f797de..108f7c5874 100644
--- a/apps/web/ui/layout/workspace-switcher.tsx
+++ b/apps/web/ui/layout/workspace-switcher.tsx
@@ -140,13 +140,15 @@ function WorkspaceList({
<div className="relative mt-1 max-h-72 w-full space-y-0.5 overflow-auto rounded-md bg-white p-2 text-base sm:w-60 sm:text-sm sm:shadow-lg">
<div className="flex items-center justify-between px-2 pb-1">
<p className="text-xs text-gray-500">My Workspaces</p>
- <Link
- href="/workspaces"
- onClick={() => setOpenPopover(false)}
- className="rounded-md border border-gray-200 px-2 py-1 text-xs transition-colors hover:bg-gray-100"
- >
- View All
- </Link>
+ {workspaces.length > 0 && (
+ <Link
+ href="/workspaces"
+ onClick={() => setOpenPopover(false)}
+ className="rounded-md border border-gray-200 px-2 py-1 text-xs transition-colors hover:bg-gray-100"
+ >
+ View All
+ </Link>
+ )}
</div>
{workspaces.map(({ id, name, slug, logo }) => {
return (