Skip to content

Commit ff5c846

Browse files
Switch to type guard
1 parent ed9e39d commit ff5c846

File tree

1 file changed

+6
-2
lines changed
  • apps/sim/app/api/auth/socket-token

1 file changed

+6
-2
lines changed

apps/sim/app/api/auth/socket-token/route.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ export async function POST() {
2525
} catch (error) {
2626
// better-auth's sessionMiddleware throws APIError("UNAUTHORIZED") with no message
2727
// when the session is missing/expired — surface this as a 401, not a 500.
28-
const apiError = error as { statusCode?: number; status?: string }
29-
if (apiError.statusCode === 401 || apiError.status === 'UNAUTHORIZED') {
28+
if (
29+
error instanceof Error &&
30+
('statusCode' in error || 'status' in error) &&
31+
((error as Record<string, unknown>).statusCode === 401 ||
32+
(error as Record<string, unknown>).status === 'UNAUTHORIZED')
33+
) {
3034
logger.warn('Socket token request with invalid/expired session')
3135
return NextResponse.json({ error: 'Authentication required' }, { status: 401 })
3236
}

0 commit comments

Comments
 (0)