MCPcopy
hub / github.com/npmx-dev/npmx.dev / getOAuthSession

Function getOAuthSession

server/utils/atproto/oauth.ts:101–126  ·  view source on GitHub ↗
(event: H3Event)

Source from the content-addressed store, hash-verified

99}
100
101async function getOAuthSession(event: H3Event): Promise<{
102 oauthSession: OAuthSession | undefined
103 serverSession: SessionManager<UserServerSession>
104}> {
105 const serverSession = await useServerSession(event)
106
107 try {
108 const currentSession = serverSession.data
109 // TODO (jg): why can a session be `{}`?
110 if (!currentSession || !currentSession.public?.did) {
111 return { oauthSession: undefined, serverSession }
112 }
113
114 const oauthSession = await event.context.oauthClient.restore(currentSession.public.did)
115 return { oauthSession, serverSession }
116 } catch (error) {
117 // Log error safely without using util.inspect on potentially problematic objects
118 // The @atproto library creates error objects with getters that crash Node's util.inspect
119 // eslint-disable-next-line no-console
120 console.error(
121 '[oauth] Failed to get session:',
122 error instanceof Error ? error.message : 'Unknown error',
123 )
124 return { oauthSession: undefined, serverSession }
125 }
126}
127
128/**
129 * Throws if the logged in OAuth Session does not have the required scopes.

Callers 1

Calls 1

useServerSessionFunction · 0.85

Tested by

no test coverage detected