Skip to content

Commit 453683c

Browse files
atrakhConvex, Inc.
authored andcommitted
dashboard: redirect to vercel projects in more scenarios (#43152)
GitOrigin-RevId: 96405a9ab576b9b7a94110ddee683fc663e5321c
1 parent 8de3821 commit 453683c

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

npm-packages/dashboard/src/pages/[[...route]].tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ function Main() {
6262
if (query.projectId) {
6363
return <RedirectToProjectById id={query.projectId as string} />;
6464
}
65+
66+
if (!!query.vercelLogin && firstVercelTeam) {
67+
void push(`/t/${firstVercelTeam.slug}`);
68+
return <Loading />;
69+
}
6570
return <RedirectToTeam />;
6671
}
6772

npm-packages/dashboard/src/pages/api/auth/callback.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,6 @@ export default async function handler(
1919

2020
const { resource_id, path, url } = req.query;
2121

22-
let returnTo = state && !state.startsWith("/api") ? state : "/";
23-
24-
// url is a query parameter that is only set by the Vercel auth flow
25-
// if it is set, and looks like a redirect to the device-auth flow,
26-
// we redirect to the device-auth flow.
27-
if (typeof url === "string" && url.startsWith("https://auth.convex.dev")) {
28-
returnTo = url;
29-
} else if (typeof path === "string" || typeof resource_id === "string") {
30-
const key = typeof path === "string" ? "vercelPath" : "projectId";
31-
const value = typeof path === "string" ? path : resource_id;
32-
returnTo = addQueryParam(returnTo, key, value as string);
33-
}
34-
3522
if (!code) {
3623
return res.status(400).send("No code provided");
3724
}
@@ -47,7 +34,7 @@ export default async function handler(
4734
},
4835
});
4936

50-
const { sealedSession } = authenticateResponse;
37+
const { sealedSession, authenticationMethod } = authenticateResponse;
5138

5239
// Store the session in a cookie
5340
const secure =
@@ -59,7 +46,23 @@ export default async function handler(
5946
`wos-session=${sealedSession}; Path=/; HttpOnly;${secure} SameSite=Lax; Max-Age=${60 * 60 * 24 * 14}`,
6047
);
6148

62-
// Use the information in `user` for further business logic.
49+
let returnTo = state && !state.startsWith("/api") ? state : "/";
50+
51+
// url is a query parameter that is only set by the Vercel auth flow
52+
// if it is set, and looks like a redirect to the device-auth flow,
53+
// we redirect to the device-auth flow.
54+
if (typeof url === "string" && url.startsWith("https://auth.convex.dev")) {
55+
returnTo = url;
56+
} else if (typeof path === "string" || typeof resource_id === "string") {
57+
const key = typeof path === "string" ? "vercelPath" : "projectId";
58+
const value = typeof path === "string" ? path : resource_id;
59+
returnTo = addQueryParam(returnTo, key, value as string);
60+
}
61+
62+
// @ts-expect-error VercelOAuth is a real authentication method
63+
if (authenticationMethod === "VercelOAuth") {
64+
returnTo = addQueryParam(returnTo, "vercelLogin", "true");
65+
}
6366

6467
// Redirect the user to the homepage
6568
res.redirect(returnTo);

0 commit comments

Comments
 (0)