mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-30 09:18:01 -05:00
remove random error code
This commit is contained in:
@@ -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 })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user