@@ -12,7 +12,7 @@ import { causeIsDie, exitIsFail, exitIsSuccess } from 'effect/Micro';
1212
1313import { authorizeµ , createParAuthorizeUrlµ } from './authorize.request.js' ;
1414import { buildTokenExchangeµ } from './exchange.request.js' ;
15- import { createClientStore , createTokenError } from './client.store.utils.js' ;
15+ import { createClientStore , createTokenError , runMicroExit } from './client.store.utils.js' ;
1616import { isExpiryWithinThreshold } from './token.utils.js' ;
1717import { logoutµ } from './logout.request.js' ;
1818import { oidcApi } from './oidc.api.js' ;
@@ -35,7 +35,6 @@ import type {
3535import type { OauthTokens , OidcConfig } from './config.types.js' ;
3636import type { AuthorizationError , AuthorizationSuccess } from './authorize.request.types.js' ;
3737import type { TokenExchangeErrorResponse } from './exchange.types.js' ;
38- import { SessionCheckResponseType } from './session.types.js' ;
3938import type { SessionCheckOptions , SessionCheckSuccess } from './session.types.js' ;
4039
4140/**
@@ -258,20 +257,7 @@ export async function oidc<ActionType extends ActionTypes = ActionTypes>({
258257 } ) ,
259258 ) ;
260259
261- const result = await Micro . runPromiseExit ( getTokensµ ) ;
262-
263- if ( exitIsSuccess ( result ) ) {
264- return result . value ;
265- } else if ( exitIsFail ( result ) ) {
266- return result . cause . error ;
267- } else {
268- const defect = causeIsDie ( result . cause ) ? result . cause . defect : undefined ;
269- return {
270- error : 'Token Exchange failure' ,
271- message : defect instanceof Error ? defect . message : String ( defect ?? 'Unknown defect' ) ,
272- type : 'exchange_error' ,
273- } ;
274- }
260+ return runMicroExit ( getTokensµ , 'Token Exchange failure' , 'exchange_error' ) ;
275261 } ,
276262
277263 /**
@@ -457,20 +443,7 @@ export async function oidc<ActionType extends ActionTypes = ActionTypes>({
457443 ) ,
458444 ) ;
459445
460- const result = await Micro . runPromiseExit ( revokeµ ) ;
461-
462- if ( exitIsSuccess ( result ) ) {
463- return result . value ;
464- } else if ( exitIsFail ( result ) ) {
465- return result . cause . error ;
466- } else {
467- const defect = causeIsDie ( result . cause ) ? result . cause . defect : undefined ;
468- return {
469- error : 'Token revocation failure' ,
470- message : defect instanceof Error ? defect . message : String ( defect ?? 'Unknown defect' ) ,
471- type : 'auth_error' ,
472- } ;
473- }
446+ return runMicroExit ( revokeµ , 'Token revocation failure' , 'auth_error' ) ;
474447 } ,
475448 } ,
476449
@@ -533,20 +506,7 @@ export async function oidc<ActionType extends ActionTypes = ActionTypes>({
533506 } ) ,
534507 ) ;
535508
536- const result = await Micro . runPromiseExit ( info ) ;
537-
538- if ( exitIsSuccess ( result ) ) {
539- return result . value ;
540- } else if ( exitIsFail ( result ) ) {
541- return result . cause . error ;
542- } else {
543- const defect = causeIsDie ( result . cause ) ? result . cause . defect : undefined ;
544- return {
545- error : 'User Info retrieval failure' ,
546- message : defect instanceof Error ? defect . message : String ( defect ?? 'Unknown defect' ) ,
547- type : 'auth_error' ,
548- } ;
549- }
509+ return runMicroExit ( info , 'User Info retrieval failure' , 'auth_error' ) ;
550510 } ,
551511
552512 /**
@@ -587,38 +547,24 @@ export async function oidc<ActionType extends ActionTypes = ActionTypes>({
587547 return createTokenError ( 'no_id_token' ) ;
588548 }
589549
590- const result = await Micro . runPromiseExit (
550+ return runMicroExit (
591551 logoutµ ( { tokens, config, wellknown, store, storageClient } ) ,
552+ 'Logout_Failure' ,
553+ 'auth_error' ,
592554 ) ;
593-
594- if ( exitIsSuccess ( result ) ) {
595- return result . value ;
596- } else if ( exitIsFail ( result ) ) {
597- return result . cause . error ;
598- } else {
599- const defect = causeIsDie ( result . cause ) ? result . cause . defect : undefined ;
600- return {
601- error : 'Logout_Failure' ,
602- message : defect instanceof Error ? defect . message : String ( defect ?? 'Unknown defect' ) ,
603- type : 'auth_error' ,
604- } ;
605- }
606555 } ,
607- } ,
608556
609- /**
610- * An object containing methods for OIDC session management
611- */
612- session : {
613557 /**
614- * @method check
558+ * @method session
615559 * @description Checks whether the user has an active session at the authorization server
616560 * using a hidden iframe with prompt=none. Supports response_type=none (default)
617561 * and response_type=id_token.
618562 * @param {SessionCheckOptions } options - Optional parameters for the session check.
619563 * @returns {Promise<SessionCheckSuccess | GenericError> } - Never throws; returns a typed result.
620564 */
621- check : async ( options ?: SessionCheckOptions ) : Promise < SessionCheckSuccess | GenericError > => {
565+ session : async (
566+ options ?: SessionCheckOptions ,
567+ ) : Promise < SessionCheckSuccess | GenericError > => {
622568 const state = store . getState ( ) ;
623569 const wellknown = wellknownSelector ( wellknownUrl , state ) ;
624570
@@ -631,24 +577,11 @@ export async function oidc<ActionType extends ActionTypes = ActionTypes>({
631577 }
632578
633579 const micro =
634- options ?. responseType === SessionCheckResponseType . IdToken
580+ options ?. responseType === 'id_token'
635581 ? sessionCheckIdTokenµ ( wellknown , config , store , storageClient , log , options )
636582 : sessionCheckNoneµ ( wellknown , config , store , storageClient , log , options ) ;
637583
638- const result = await Micro . runPromiseExit ( micro ) ;
639-
640- if ( exitIsSuccess ( result ) ) {
641- return result . value ;
642- } else if ( exitIsFail ( result ) ) {
643- return result . cause . error ;
644- } else {
645- const defect = causeIsDie ( result . cause ) ? result . cause . defect : undefined ;
646- return {
647- error : 'Session check failure' ,
648- message : defect instanceof Error ? defect . message : String ( defect ?? 'Unknown defect' ) ,
649- type : 'unknown_error' ,
650- } ;
651- }
584+ return runMicroExit ( micro , 'Session check failure' , 'unknown_error' ) ;
652585 } ,
653586 } ,
654587 } ;
0 commit comments