( sessionData: string, cookiePassword: string, jwks: CachedRemoteJWKSet, )
| 208 | ); |
| 209 | |
| 210 | const verifySealedSessionLocally = ( |
| 211 | sessionData: string, |
| 212 | cookiePassword: string, |
| 213 | jwks: CachedRemoteJWKSet, |
| 214 | ): Effect.Effect<LocalSessionVerification, ServiceAdapterError> => |
| 215 | Effect.gen(function* () { |
| 216 | const unsealed = yield* Effect.tryPromise({ |
| 217 | try: () => unsealWorkOSSession(sessionData, cookiePassword), |
| 218 | catch: (cause) => new LocalSessionCookieError({ cause }), |
| 219 | }).pipe( |
| 220 | Effect.catchTag("LocalSessionCookieError", () => Effect.succeed(null as unknown | null)), |
| 221 | ); |
| 222 | if (!unsealed) return { _tag: "InvalidCookie" }; |
| 223 | |
| 224 | const session = Option.match(decodeSealedSessionPayload(unsealed), { |
| 225 | onNone: (): SealedSessionPayload | null => null, |
| 226 | onSome: (payload) => payload, |
| 227 | }); |
| 228 | if (!session) return { _tag: "InvalidCookie" }; |
| 229 | |
| 230 | const verified = yield* verifyJwtWithRefreshRetry(session.accessToken, jwks); |
| 231 | if (!verified) return { _tag: "Refresh" }; |
| 232 | |
| 233 | const claims = Option.getOrNull(decodeJwtClaims(decodeJwt(session.accessToken))); |
| 234 | if (!claims) return { _tag: "Refresh" }; |
| 235 | |
| 236 | return { |
| 237 | _tag: "Valid", |
| 238 | session, |
| 239 | organizationId: claims.org_id, |
| 240 | sessionId: claims.sid, |
| 241 | }; |
| 242 | }); |
| 243 | |
| 244 | const completedListMetadata = { |
| 245 | before: null, |
no test coverage detected