Skip to content

Commit f92a445

Browse files
committed
fix: clean up some logout messages
1 parent d732a97 commit f92a445

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

backend/src/api/org.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { findOrganizationForRepository } from '@codebuff/billing'
22
import { z } from 'zod/v4'
3+
import { INVALID_AUTH_TOKEN_MESSAGE } from '@codebuff/common/constants'
34

45
import { logger } from '../util/logger'
56
import { extractAuthTokenFromHeader } from '../util/auth-helpers'
@@ -37,7 +38,7 @@ async function isRepoCoveredHandler(
3738
const userId = await getUserIdFromAuthToken(authToken)
3839

3940
if (!userId) {
40-
return res.status(401).json({ error: 'Invalid authentication token' })
41+
return res.status(401).json({ error: INVALID_AUTH_TOKEN_MESSAGE })
4142
}
4243

4344
// Check if repository is covered by an organization

backend/src/api/usage.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import db from '@codebuff/common/db'
33
import * as schema from '@codebuff/common/db/schema'
44
import { eq } from 'drizzle-orm'
55
import { z } from 'zod/v4'
6+
import { INVALID_AUTH_TOKEN_MESSAGE } from '@codebuff/common/constants'
67

78
import { checkAuth } from '../util/check-auth'
89
import { logger } from '../util/logger'
@@ -61,7 +62,10 @@ async function usageHandler(
6162
: undefined
6263

6364
if (!userId) {
64-
return res.status(401).json({ message: 'Authentication failed' })
65+
const message = authToken
66+
? INVALID_AUTH_TOKEN_MESSAGE
67+
: 'Authentication failed'
68+
return res.status(401).json({ message })
6569
}
6670

6771
// If orgId is provided, return organization usage data

common/src/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export const AGENT_DEFINITION_FILE = 'agent-definition.d.ts'
1010

1111
export const API_KEY_ENV_VAR = 'CODEBUFF_API_KEY'
1212

13+
export const INVALID_AUTH_TOKEN_MESSAGE =
14+
'Invalid auth token. You may have been logged out from the web portal. Please log in again.'
15+
1316
// Enable async agents to run tool calls even when main user input is cancelled
1417
export const ASYNC_AGENTS_ENABLED = true
1518

packages/internal/src/utils/auth.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import db from '@codebuff/common/db'
22
import * as schema from '@codebuff/common/db/schema'
33
import { eq } from 'drizzle-orm'
44

5+
import { INVALID_AUTH_TOKEN_MESSAGE } from '@codebuff/common/constants'
6+
57
// List of admin user emails - single source of truth
68
const CODEBUFF_ADMIN_USER_EMAILS = [
79
'venkateshrameshkumar+1@gmail.com',
@@ -81,7 +83,7 @@ export async function checkAuthToken({
8183
success: false,
8284
error: {
8385
type: 'invalid-token',
84-
message: 'Invalid auth token',
86+
message: INVALID_AUTH_TOKEN_MESSAGE,
8587
},
8688
}
8789
}

web/src/app/api/auth/cli/logout/route.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as schema from '@codebuff/common/db/schema'
33
import { and, eq } from 'drizzle-orm'
44
import { NextResponse } from 'next/server'
55
import { z } from 'zod/v4'
6+
import { INVALID_AUTH_TOKEN_MESSAGE } from '@codebuff/common/constants'
67

78
import { logger } from '@/util/logger'
89

@@ -36,7 +37,12 @@ export async function POST(req: Request) {
3637
})
3738

3839
if (validDeletion.length === 0) {
39-
return NextResponse.json({ error: 'Invalid session' }, { status: 401 })
40+
return NextResponse.json(
41+
{
42+
error: INVALID_AUTH_TOKEN_MESSAGE,
43+
},
44+
{ status: 401 }
45+
)
4046
}
4147

4248
// Then reset sig_hash to null

0 commit comments

Comments
 (0)