remove random error code

This commit is contained in:
Vikhyath Mondreti
2026-01-29 16:56:56 -08:00
parent fc1ca1e36b
commit 7d23e2363d
2 changed files with 7 additions and 18 deletions

View File

@@ -4,32 +4,22 @@ import { auth } from '@/lib/auth'
import { isAuthDisabled } from '@/lib/core/config/feature-flags'
export async function POST() {
try {
if (isAuthDisabled) {
return NextResponse.json({ token: 'anonymous-socket-token' })
}
if (isAuthDisabled) {
return NextResponse.json({ token: 'anonymous-socket-token' })
}
try {
const hdrs = await headers()
const response = await auth.api.generateOneTimeToken({
headers: hdrs,
})
if (!response?.token) {
// No token usually means invalid/expired session
return NextResponse.json({ error: 'Authentication required' }, { status: 401 })
}
return NextResponse.json({ token: response.token })
} catch (error) {
// Check if it's an auth-related error
const errorMessage = error instanceof Error ? error.message : String(error)
if (
errorMessage.includes('session') ||
errorMessage.includes('unauthorized') ||
errorMessage.includes('unauthenticated')
) {
return NextResponse.json({ error: 'Authentication required' }, { status: 401 })
}
return NextResponse.json({ error: 'Failed to generate token' }, { status: 500 })
} catch {
return NextResponse.json({ error: 'Authentication required' }, { status: 401 })
}
}

View File

@@ -155,8 +155,7 @@ export function SocketProvider({ children, user }: SocketProviderProps) {
headers: { 'cache-control': 'no-store' },
})
if (!res.ok) {
// 401/403 indicates session expiry - don't keep retrying
if (res.status === 401 || res.status === 403) {
if (res.status === 401) {
throw new Error('Authentication required')
}
throw new Error('Failed to generate socket token')