Use external DB/Redis in compose and preserve auth session across rebuilds
This commit is contained in:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user