(sessionData: string)
| 410 | ); |
| 411 | |
| 412 | const authenticateSealedSession = (sessionData: string) => |
| 413 | Effect.gen(function* () { |
| 414 | if (!sessionData) return null; |
| 415 | |
| 416 | const session = workos.userManagement.loadSealedSession({ |
| 417 | sessionData, |
| 418 | cookiePassword, |
| 419 | }); |
| 420 | |
| 421 | const local = yield* withServiceLogging( |
| 422 | "workos.session.local_verify", |
| 423 | workosErrorFromFailure, |
| 424 | verifySealedSessionLocally(sessionData, cookiePassword, sessionJwks), |
| 425 | ); |
| 426 | |
| 427 | if (isLocalSessionValid(local)) { |
| 428 | return { |
| 429 | userId: local.session.user.id, |
| 430 | email: local.session.user.email, |
| 431 | firstName: local.session.user.firstName, |
| 432 | lastName: local.session.user.lastName, |
| 433 | avatarUrl: local.session.user.profilePictureUrl, |
| 434 | organizationId: local.organizationId, |
| 435 | sessionId: local.sessionId, |
| 436 | refreshedSession: undefined as string | undefined, |
| 437 | }; |
| 438 | } |
| 439 | |
| 440 | if (isLocalSessionInvalidCookie(local)) return null; |
| 441 | |
| 442 | // Try refreshing |
| 443 | const refreshed = yield* use("session.refresh", () => session.refresh()).pipe( |
| 444 | Effect.orElseSucceed(() => ({ authenticated: false as const })), |
| 445 | ); |
| 446 | |
| 447 | if (!refreshed.authenticated || !("sealedSession" in refreshed) || !refreshed.sealedSession) |
| 448 | return null; |
| 449 | |
| 450 | return { |
| 451 | userId: refreshed.user.id, |
| 452 | email: refreshed.user.email, |
| 453 | firstName: refreshed.user.firstName, |
| 454 | lastName: refreshed.user.lastName, |
| 455 | avatarUrl: refreshed.user.profilePictureUrl, |
| 456 | organizationId: refreshed.organizationId, |
| 457 | sessionId: refreshed.sessionId, |
| 458 | refreshedSession: refreshed.sealedSession, |
| 459 | }; |
| 460 | }); |
| 461 | |
| 462 | return { |
| 463 | getAuthorizationUrl: (redirectUri: string, state?: string) => |
no test coverage detected