( handler: EventHandlerWithOAuthSession<T, D>, )
| 143 | } |
| 144 | |
| 145 | export 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 | } |
no test coverage detected