Skip to content

Commit 765297c

Browse files
committed
fix: handle errors from oauth client
1 parent 3a66b54 commit 765297c

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

server/utils/atproto/oauth.ts

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,33 @@ type EventHandlerWithOAuthSession<T extends EventHandlerRequest, D> = (
4343
) => Promise<D>
4444

4545
async function getOAuthSession(event: H3Event): Promise<OAuthSession | undefined> {
46-
const clientMetadata = getOauthClientMetadata()
47-
const serverSession = await useServerSession(event)
48-
const { stateStore, sessionStore } = useOAuthStorage(serverSession)
46+
try {
47+
const clientMetadata = getOauthClientMetadata()
48+
const serverSession = await useServerSession(event)
49+
const { stateStore, sessionStore } = useOAuthStorage(serverSession)
4950

50-
const client = new NodeOAuthClient({
51-
stateStore,
52-
sessionStore,
53-
clientMetadata,
54-
requestLock: getOAuthLock(),
55-
})
51+
const client = new NodeOAuthClient({
52+
stateStore,
53+
sessionStore,
54+
clientMetadata,
55+
requestLock: getOAuthLock(),
56+
})
5657

57-
const currentSession = await sessionStore.get()
58-
if (!currentSession) return undefined
58+
const currentSession = await sessionStore.get()
59+
if (!currentSession) return undefined
5960

60-
// restore using the subject
61-
return await client.restore(currentSession.tokenSet.sub)
61+
// restore using the subject
62+
return await client.restore(currentSession.tokenSet.sub)
63+
} catch (error) {
64+
// Log error safely without using util.inspect on potentially problematic objects
65+
// The @atproto library creates error objects with getters that crash Node's util.inspect
66+
// eslint-disable-next-line no-console
67+
console.error(
68+
'[oauth] Failed to get session:',
69+
error instanceof Error ? error.message : 'Unknown error',
70+
)
71+
return undefined
72+
}
6273
}
6374

6475
/**

0 commit comments

Comments
 (0)