Use external DB/Redis in compose and preserve auth session across rebuilds

This commit is contained in:
Ruslan Bakiev
2026-02-19 17:01:00 +07:00
parent f6fd11b3c4
commit a25049989c
4 changed files with 37 additions and 44 deletions

View File

@@ -69,7 +69,24 @@ export async function getAuthContext(event: H3Event): Promise<AuthContext> {
});
if (!conv) {
throw createError({ statusCode: 401, statusMessage: "Unauthorized" });
// Recover from stale conversation cookie after rebuild/reset:
// reuse latest available conversation (or recreate default one) and refresh cookie.
const fallback =
(await prisma.chatConversation.findFirst({
where: { teamId: team.id, createdByUserId: user.id },
orderBy: { updatedAt: "desc" },
})) ||
(await prisma.chatConversation.create({
data: { id: `pilot-${team.id}`, teamId: team.id, createdByUserId: user.id, title: "Pilot" },
}));
setSession(event, {
teamId: team.id,
userId: user.id,
conversationId: fallback.id,
});
return { teamId: team.id, userId: user.id, conversationId: fallback.id };
}
return { teamId: team.id, userId: user.id, conversationId: conv.id };