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

Function authenticateSealedSession

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

Source from the content-addressed store, hash-verified

443 );
444
445 const authenticateSealedSession = (sessionData: string) =>
446 Effect.gen(function* () {
447 if (!sessionData) return null;
448
449 const session = workos.userManagement.loadSealedSession({
450 sessionData,
451 cookiePassword,
452 });
453
454 const local = yield* withServiceLogging(
455 "workos.session.local_verify",
456 workosErrorFromFailure,
457 verifySealedSessionLocally(sessionData, cookiePassword, sessionJwks),
458 );
459
460 if (isLocalSessionValid(local)) {
461 return {
462 userId: local.session.user.id,
463 email: local.session.user.email,
464 firstName: local.session.user.firstName,
465 lastName: local.session.user.lastName,
466 avatarUrl: local.session.user.profilePictureUrl,
467 organizationId: local.organizationId,
468 sessionId: local.sessionId,
469 refreshedSession: undefined as string | undefined,
470 };
471 }
472
473 if (isLocalSessionInvalidCookie(local)) return null;
474
475 // Try refreshing
476 const refreshed = yield* use("session.refresh", () => session.refresh()).pipe(
477 Effect.orElseSucceed(() => ({ authenticated: false as const })),
478 );
479
480 if (!refreshed.authenticated || !("sealedSession" in refreshed) || !refreshed.sealedSession)
481 return null;
482
483 return {
484 userId: refreshed.user.id,
485 email: refreshed.user.email,
486 firstName: refreshed.user.firstName,
487 lastName: refreshed.user.lastName,
488 avatarUrl: refreshed.user.profilePictureUrl,
489 organizationId: refreshed.organizationId,
490 sessionId: refreshed.sessionId,
491 refreshedSession: refreshed.sealedSession,
492 };
493 });
494
495 return {
496 /** List factors belonging to this user; callers cannot supply another user's factor. */

Callers 1

workos.tsFile · 0.85

Calls 3

withServiceLoggingFunction · 0.90
useFunction · 0.70

Tested by

no test coverage detected