Open the bot last visited, else the coordinator

`/admin/bots` sent the super admin to the coordinator and everyone else to
their latest bot, which lost the thread each time the tab was reopened. The
conversation pages now record where the browser is in two HttpOnly cookies
(`cobble_last_visited_bot_id`, `..._workspace_id`, a year, `Secure` only over
HTTPS), and the landing page opens that conversation again, in its workspace
when it was one.

A stale cookie can't loop: `grabReachableConversation` re-checks it with
`grabUserConversation`, the gate the conversation pages use, so a revoked
grant, a deleted bot or an archived workspace falls back to the coordinator
(super admin) or the latest bot, first workspace, empty page. Signing out
clears both cookies so the next user on that browser doesn't land in the
previous one's conversation.
This commit is contained in:
2026-10-22 11:18:19 +01:00
parent a8d8b680ad
commit 16f1e7904a
14 changed files with 402 additions and 10 deletions
+7
View File
@@ -10,10 +10,17 @@ describe("AppData auth constants", () => {
expect(AppData["AuthCSRFCookieName"]).toBe(
`${SiteData["SiteSlug"]}_auth_csrf`,
);
expect(AppData["LastVisitedBotCookieName"]).toBe(
`${SiteData["SiteSlug"]}_last_visited_bot_id`,
);
expect(AppData["LastVisitedWorkspaceCookieName"]).toBe(
`${SiteData["SiteSlug"]}_last_visited_workspace_id`,
);
});
test("expiry and limits are positive", () => {
expect(AppData["AuthExpiryDays"]).toBeGreaterThan(0);
expect(AppData["LastVisitedCookieMaxAgeSeconds"]).toBeGreaterThan(0);
expect(AppData["DefaultQueryLimit"]).toBeGreaterThan(0);
});
+10
View File
@@ -54,6 +54,16 @@ export const AppData = {
*/
BuildCookieName: `${SiteData["SiteSlug"]}_build`,
BuildCookieMaxAgeSeconds: 365 * 24 * 60 * 60,
/**
* The conversation this browser was last in: `/admin/bots` opens it
* again, falling back to the coordinator (super admin) or the latest
* bot when the grant is gone. Two small ids, so the workspace one
* stays empty for a bot's own chat. `HttpOnly`: only the server reads
* them.
*/
LastVisitedBotCookieName: `${SiteData["SiteSlug"]}_last_visited_bot_id`,
LastVisitedWorkspaceCookieName: `${SiteData["SiteSlug"]}_last_visited_workspace_id`,
LastVisitedCookieMaxAgeSeconds: 365 * 24 * 60 * 60,
AuthExpiryDays: 60,
APICrudBasePath: "/api/admin/crud",
ForcePrivateHeaderKey: `x-${SiteData["SiteSlug"]}-force-private`,