Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ async function start() {
const app = await NestFactory.create(AppModule, {
rawBody: true,
cors: {
...(!process.env.NOT_SECURED ? { credentials: true } : {}),
allowedHeaders: ['Content-Type', 'Authorization', 'x-copilotkit-runtime-client-gql-version'],
credentials: true,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Backend CORS unconditionally requires credentials, but frontend does not send them in dev mode (NOT_SECURED=true), causing CORS errors.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

The PR's change to CORS configuration unconditionally sets credentials: true on the backend. However, in development mode (process.env.NOT_SECURED=true), the frontend explicitly does not send credentials: 'include' in its fetch requests. This mismatch causes browsers to block responses with CORS errors, preventing authentication from working in dev mode. This contradicts the PR's goal of fixing sign-in issues in development.

💡 Suggested Fix

Revert the CORS configuration change to preserve conditional logic: ...(process.env.NOT_SECURED ? {} : { credentials: true }) instead of unconditionally setting credentials: true.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: apps/backend/src/main.ts#L23

Potential issue: The PR's change to CORS configuration unconditionally sets
`credentials: true` on the backend. However, in development mode
(`process.env.NOT_SECURED=true`), the frontend explicitly does *not* send `credentials:
'include'` in its fetch requests. This mismatch causes browsers to block responses with
CORS errors, preventing authentication from working in dev mode. This contradicts the
PR's goal of fixing sign-in issues in development.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 196827

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it worked for me when I set NOT_SECURED to TRUE. If you want I can change it back, because most important change here is with headers

allowedHeaders: ['Content-Type', 'Authorization', 'x-copilotkit-runtime-client-gql-version', ...(process.env.NOT_SECURED ? ['auth', 'showorg', 'impersonate'] : [])],
exposedHeaders: [
'reload',
'onboarding',
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,10 @@
},
"pnpm": {
"onlyBuiltDependencies": [
"bcrypt"
"@prisma/client",
"@prisma/engines",
"bcrypt",
"prisma"
]
}
}