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

Function eventHandlerWithOAuthSession

server/utils/atproto/oauth.ts:145–164  ·  view source on GitHub ↗
(
  handler: EventHandlerWithOAuthSession<T, D>,
)

Source from the content-addressed store, hash-verified

143}
144
145export function eventHandlerWithOAuthSession<T extends EventHandlerRequest, D>(
146 handler: EventHandlerWithOAuthSession<T, D>,
147) {
148 return defineEventHandler(async event => {
149 const { oauthSession, serverSession } = await getOAuthSession(event)
150 const publicData = serverSession.data.public
151 // User was authenticated at one point, but was not able to restore
152 // the session to the PDS
153 if (!oauthSession && publicData) {
154 // cleans up our server side session store
155 await serverSession.clear()
156 throw createError({
157 status: 401,
158 message: 'User needs to re authenticate',
159 })
160 }
161
162 return await handler(event, oauthSession, serverSession)
163 })
164}

Callers 6

like.post.tsFile · 0.85
like.delete.tsFile · 0.85
index.put.tsFile · 0.85
[...pkg].get.tsFile · 0.85
session.delete.tsFile · 0.85
session.get.tsFile · 0.85

Calls 2

getOAuthSessionFunction · 0.85
clearMethod · 0.80

Tested by

no test coverage detected