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:
@@ -0,0 +1,41 @@
|
||||
import { AppData } from "@/src/data/app-data";
|
||||
import type { CookieOptions } from "./cookies";
|
||||
|
||||
type Params = {
|
||||
bot_id: number | string;
|
||||
/**
|
||||
* Null or undefined: the bot's own chat.
|
||||
*/
|
||||
workspace_id?: number | string | null;
|
||||
/**
|
||||
* From `isSecureRequest`, so plain HTTP over a VPN still keeps them.
|
||||
*/
|
||||
secure: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* The cookies that remember the conversation this browser is in, for
|
||||
* `setCookies`: read back by `readLastVisitedBot` on the bots' landing page.
|
||||
* `HttpOnly`, since only the server reads them, and they hold nothing but
|
||||
* two ids.
|
||||
*/
|
||||
export default function lastVisitedBotCookies({
|
||||
bot_id,
|
||||
workspace_id,
|
||||
secure,
|
||||
}: Params): CookieOptions[] {
|
||||
return [
|
||||
{
|
||||
name: AppData["LastVisitedBotCookieName"],
|
||||
value: String(bot_id),
|
||||
secure,
|
||||
maxAge: AppData["LastVisitedCookieMaxAgeSeconds"],
|
||||
},
|
||||
{
|
||||
name: AppData["LastVisitedWorkspaceCookieName"],
|
||||
value: workspace_id ? String(workspace_id) : "",
|
||||
secure,
|
||||
maxAge: AppData["LastVisitedCookieMaxAgeSeconds"],
|
||||
},
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user