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.

fix /login redirect bug

Steven Teyd56e99aaa6f6
diff --git a/apps/web/lib/middleware/app.ts b/apps/web/lib/middleware/app.ts
index 2f2b49b84b..73c2c1d538 100644
--- a/apps/web/lib/middleware/app.ts
+++ b/apps/web/lib/middleware/app.ts
@@ -5,7 +5,7 @@ import { getDefaultWorkspace } from "./utils/get-default-workspace";
import { getUserViaToken } from "./utils/get-user-via-token";
export default async function AppMiddleware(req: NextRequest) {
- const { path, fullPath } = parse(req);
+ const { path, fullPath, searchParamsString } = parse(req);
const user = await getUserViaToken(req);
// if there's no user and the path isn't /login or /register, redirect to /login
@@ -44,7 +44,7 @@ export default async function AppMiddleware(req: NextRequest) {
if (defaultWorkspace) {
return NextResponse.redirect(
- new URL(`/${defaultWorkspace}${fullPath}`, req.url),
+ new URL(`/${defaultWorkspace}${searchParamsString}`, req.url),
);
} else {
return NextResponse.redirect(new URL("/workspaces", req.url));
diff --git a/apps/web/lib/middleware/utils/parse.ts b/apps/web/lib/middleware/utils/parse.ts
index cc68b7f950..3d6db70540 100644
--- a/apps/web/lib/middleware/utils/parse.ts
+++ b/apps/web/lib/middleware/utils/parse.ts
@@ -15,13 +15,12 @@ export const parse = (req: NextRequest) => {
// fullPath is the full URL path (along with search params)
const searchParams = req.nextUrl.searchParams.toString();
- const fullPath = `${path}${
- searchParams.length > 0 ? `?${searchParams}` : ""
- }`;
+ const searchParamsString = searchParams.length > 0 ? `?${searchParams}` : "";
+ const fullPath = `${path}${searchParamsString}`;
// Here, we are using decodeURIComponent to handle foreign languages like Hebrew
const key = decodeURIComponent(path.split("/")[1]); // key is the first part of the path (e.g. dub.co/stats/github -> stats)
const fullKey = decodeURIComponent(path.slice(1)); // fullKey is the full path without the first slash (to account for multi-level subpaths, e.g. d.to/github/repo -> github/repo)
- return { domain, path, fullPath, key, fullKey };
+ return { domain, path, fullPath, key, fullKey, searchParamsString };
};