Skip to content

Commit 92ae761

Browse files
fix(web): Fix issue where creating a new Ask thread would result in a 404 (#641)
1 parent f1dd16b commit 92ae761

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Fixed issue where single quotes could not be used in search queries. [#629](https://github.com/sourcebot-dev/sourcebot/pull/629)
1515
- Fixed issue where files with special characters would fail to load. [#636](https://github.com/sourcebot-dev/sourcebot/issues/636)
1616
- Fixed Ask performance issues. [#632](https://github.com/sourcebot-dev/sourcebot/pull/632)
17+
- Fixed regression where creating a new Ask thread when unauthenticated would result in a 404. [#641](https://github.com/sourcebot-dev/sourcebot/pull/641)
1718

1819
## [4.10.0] - 2025-11-24
1920

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- First, remove the NOT NULL constraint on the createdById column.
2+
ALTER TABLE "Chat" ALTER COLUMN "createdById" DROP NOT NULL;
3+
4+
-- Then, set all chats created by the guest user (id: 1) to have a NULL createdById.
5+
UPDATE "Chat" SET "createdById" = NULL WHERE "createdById" = '1';

packages/db/prisma/schema.prisma

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,8 @@ model Chat {
437437
438438
name String?
439439
440-
createdBy User @relation(fields: [createdById], references: [id], onDelete: Cascade)
441-
createdById String
440+
createdBy User? @relation(fields: [createdById], references: [id], onDelete: Cascade)
441+
createdById String?
442442
443443
createdAt DateTime @default(now())
444444
updatedAt DateTime @updatedAt

packages/web/src/features/chat/actions.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use server';
22

33
import { sew } from "@/actions";
4-
import { SOURCEBOT_GUEST_USER_ID } from "@/lib/constants";
54
import { ErrorCode } from "@/lib/errorCodes";
65
import { chatIsReadonly, notFound, ServiceError, serviceErrorResponse } from "@/lib/serviceError";
76
import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';
@@ -34,13 +33,13 @@ const logger = createLogger('chat-actions');
3433

3534
export const createChat = async () => sew(() =>
3635
withOptionalAuthV2(async ({ org, user, prisma }) => {
37-
const isGuestUser = user?.id === SOURCEBOT_GUEST_USER_ID;
36+
const isGuestUser = user === undefined;
3837

3938
const chat = await prisma.chat.create({
4039
data: {
4140
orgId: org.id,
4241
messages: [] as unknown as Prisma.InputJsonValue,
43-
createdById: user?.id ?? SOURCEBOT_GUEST_USER_ID,
42+
createdById: user?.id,
4443
visibility: isGuestUser ? ChatVisibility.PUBLIC : ChatVisibility.PRIVATE,
4544
},
4645
});

0 commit comments

Comments
 (0)