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

Function authenticateSealedSession

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

Source from the content-addressed store, hash-verified

346 );
347
348 const authenticateSealedSession = (sessionData: string) =>
349 Effect.gen(function* () {
350 if (!sessionData) return null;
351
352 const session = workos.userManagement.loadSealedSession({
353 sessionData,
354 cookiePassword,
355 });
356
357 const local = yield* withServiceLogging(
358 "workos.session.local_verify",
359 workosErrorFromFailure,
360 verifySealedSessionLocally(sessionData, cookiePassword, sessionJwks),
361 );
362
363 if (isLocalSessionValid(local)) {
364 return {
365 userId: local.session.user.id,
366 email: local.session.user.email,
367 firstName: local.session.user.firstName,
368 lastName: local.session.user.lastName,
369 avatarUrl: local.session.user.profilePictureUrl,
370 organizationId: local.organizationId,
371 sessionId: local.sessionId,
372 refreshedSession: undefined as string | undefined,
373 };
374 }
375
376 if (isLocalSessionInvalidCookie(local)) return null;
377
378 // Try refreshing
379 const refreshed = yield* use(() => session.refresh()).pipe(
380 Effect.orElseSucceed(() => ({ authenticated: false as const })),
381 );
382
383 if (!refreshed.authenticated || !("sealedSession" in refreshed) || !refreshed.sealedSession)
384 return null;
385
386 return {
387 userId: refreshed.user.id,
388 email: refreshed.user.email,
389 firstName: refreshed.user.firstName,
390 lastName: refreshed.user.lastName,
391 avatarUrl: refreshed.user.profilePictureUrl,
392 organizationId: refreshed.organizationId,
393 sessionId: refreshed.sessionId,
394 refreshedSession: refreshed.sealedSession,
395 };
396 });
397
398 return {
399 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