Skip to content

Commit e7f9d94

Browse files
committed
attempt to redirect user to new project for ephemeral startup, falling back to their project list
1 parent f46d5f6 commit e7f9d94

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/packages/next/pages/api/v2/auth/ephemeral.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { v4 } from "uuid";
77

88
import createAccount from "@cocalc/server/accounts/create-account";
99
import redeemRegistrationToken from "@cocalc/server/auth/tokens/redeem";
10+
import getProjects from "@cocalc/server/projects/get";
1011
import { signUserIn } from "./sign-in";
1112
import getParams from "lib/api/get-params";
1213

@@ -54,5 +55,17 @@ export default async function createEphemeralAccount(req, res) {
5455
return;
5556
}
5657

58+
let project_id: string | undefined;
59+
try {
60+
const [project] = await getProjects({ account_id, limit: 1 });
61+
project_id = project?.project_id;
62+
} catch (err) {
63+
// non-fatal; we just won't return a redirect target
64+
}
65+
5766
await signUserIn(req, res, account_id, { maxAge: tokenInfo.ephemeral });
67+
res.json({
68+
account_id,
69+
project_id,
70+
});
5871
}

src/packages/next/pages/ephemeral.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,18 @@ export default function EphemeralPage({ customize, token }: Props) {
4848
setInfo("");
4949
setError("");
5050
try {
51-
await apiPost("/auth/ephemeral", {
51+
const result = await apiPost("/auth/ephemeral", {
5252
registrationToken: trimmedToken,
5353
});
5454
setStatus("redirecting");
5555
setInfo("Success! Redirecting you to your workspace…");
56-
await router.push("/app");
56+
if (result?.project_id) {
57+
await router.push(
58+
`/static/app.html?target=projects/${result.project_id}/files/`,
59+
);
60+
} else {
61+
await router.push("/static/app.html?target=projects");
62+
}
5763
} catch (err) {
5864
setError(err?.message ?? `${err}`);
5965
setStatus("idle");

0 commit comments

Comments
 (0)