import { User , UserManager } from 'oidc-client' ; import { AuthSettings , mergeAuthSettings } from './AuthSettings' ; import { toStringScope } from './utils/toStringScope' ; import { createMockUser , MockUser } from './createMockUser' ; let authSettings = null ; let userManager = null ; export const getUserManager = ( ) : UserManager => { if ( userManager === null ) { throw new Error ( 'Tried to access user manager before calling configure' ) ; } return userManager ; } ; export const getAuthSettings = ( ) : AuthSettings => { if ( authSettings === null ) { throw new Error ( 'Tried to access auth settings before calling configure' ) ; } return authSettings ; } ; export const configure = ( settings ) => { authSettings = mergeAuthSettings ( settings ) ; userManager = new UserManager ( { ... authSettings , scope : toStringScope ( settings . scope ) , } ) ; return userManager ; } ; export const configureMock = ( user ? ) => { authSettings = mergeAuthSettings ( { client_id : 'test-client' , } ) ; const userInfo = createMockUser ( user ) ; const empty = ( ) => { } ; userManager = ( { getUser ( ) { return Promise . resolve ( userInfo ) ; } , signinSilent ( ) { return Promise . resolve ( userInfo ) ; } , signinRedirect : empty , events : { addUserSignedOut : empty , addUserLoaded : empty , removeUserLoaded : empty , removeUserSignedOut : empty , } , } as unknown ) as UserManager ; } ; export { User , UserManager } ;