MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / authenticateSealedSession

Function authenticateSealedSession

apps/cloud/src/auth/workos.ts:434–482  ·  view source on GitHub ↗
(sessionData: string)

Source from the content-addressed store, hash-verified

432 );
433
434 const authenticateSealedSession = (sessionData: string) =>
435 Effect.gen(function* () {
436 if (!sessionData) return null;
437
438 const session = workos.userManagement.loadSealedSession({
439 sessionData,
440 cookiePassword,
441 });
442
443 const local = yield* withServiceLogging(
444 "workos.session.local_verify",
445 workosErrorFromFailure,
446 verifySealedSessionLocally(sessionData, cookiePassword, sessionJwks),
447 );
448
449 if (isLocalSessionValid(local)) {
450 return {
451 userId: local.session.user.id,
452 email: local.session.user.email,
453 firstName: local.session.user.firstName,
454 lastName: local.session.user.lastName,
455 avatarUrl: local.session.user.profilePictureUrl,
456 organizationId: local.organizationId,
457 sessionId: local.sessionId,
458 refreshedSession: undefined as string | undefined,
459 };
460 }
461
462 if (isLocalSessionInvalidCookie(local)) return null;
463
464 // Try refreshing
465 const refreshed = yield* use("session.refresh", () => session.refresh()).pipe(
466 Effect.orElseSucceed(() => ({ authenticated: false as const })),
467 );
468
469 if (!refreshed.authenticated || !("sealedSession" in refreshed) || !refreshed.sealedSession)
470 return null;
471
472 return {
473 userId: refreshed.user.id,
474 email: refreshed.user.email,
475 firstName: refreshed.user.firstName,
476 lastName: refreshed.user.lastName,
477 avatarUrl: refreshed.user.profilePictureUrl,
478 organizationId: refreshed.organizationId,
479 sessionId: refreshed.sessionId,
480 refreshedSession: refreshed.sealedSession,
481 };
482 });
483
484 return {
485 getAuthorizationUrl: (redirectUri: string, state?: string) =>

Callers 1

workos.tsFile · 0.85

Calls 3

withServiceLoggingFunction · 0.90
useFunction · 0.70

Tested by

no test coverage detected