Skip to content

Commit 8487cd2

Browse files
atrakhConvex, Inc.
authored andcommitted
dashboard: update vercel-login redirects to work with new auth flow (#40881)
GitOrigin-RevId: ced0f810de979c2c2a52807b8fae539bebbd4ec2
1 parent 2595e31 commit 8487cd2

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ function Main() {
5858
);
5959
return <Loading />;
6060
}
61-
if (query.invoiceId) {
62-
// TODO(ENG-9453): Support this.
63-
}
6461

6562
if (query.projectId) {
6663
return <RedirectToProjectById id={query.projectId as string} />;

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,21 @@ export default async function handler(
1616
// The authorization code returned by AuthKit
1717
const code = req.query.code as string;
1818
const state = req.query.state as string; // This contains our returnTo URL
19-
const returnTo = state && !state.startsWith("/api") ? state : "/";
19+
20+
const { resource_id, path, url } = req.query;
21+
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+
}
2034

2135
if (!code) {
2236
return res.status(400).send("No code provided");
@@ -70,3 +84,8 @@ export default async function handler(
7084
// );
7185
}
7286
}
87+
88+
function addQueryParam(url: string, key: string, value: string) {
89+
const symbol = url.includes("?") ? "&" : "?";
90+
return `${url}${symbol}${key}=${value}`;
91+
}

0 commit comments

Comments
 (0)