Login
Login components include React components, context and hooks for handling user authorisation, api tokens and authorized requests.
API
Table of contents
- Components
- Modules
- Oidc client hooks
- Api tokens client hooks
- Session poller hooks
- GraphQL module hooks
- ApolloClient module hooks
- TokenizedFetch module hooks
- Generic signal hooks
- Beacon
- Signals
Components
LoginButton
| Property | Description | Default | 
|---|---|---|
| errorText | Required. An error text is shown if the OIDC server rejects the connection. | none | 
| loggingInText | Required. Text read by the screen reader when the button is clicked. | Default of the "loadingText" property of the LoadingSpinner | 
| spinnerColor | Optional. Colour of the loading spinner. | var(--color-white) | 
| redirectionProps | Properties appended to the url when redirecting. Read more in the documentation of the oidcClient login method. | none | 
| onClick | Called when the component is clicked and before the oidcClient.login() is called. | none | 
| [Table 1: Properties of the LoginButton component] |
Button text is passed and rendered as a child.
LoginCallbackHandler
| Property | Description | 
|---|---|
| children | Optional. Usually, child elements inform the user that a response is being processed. | 
| onError | Required. The function is called when a login fails. The function is called with an OidcClientError. | 
| onSuccess | Required. The function is called when a response is handled successfully. The function is called with a User object. | 
In some scenarios, when the component is rendered multiple times, usually in development mode with strict mode enabled, the onError callback is called with an error that can usually be ignored. The error indicates a login callback is already being handled. The error can be checked with the exported function isHandlingLoginCallbackError(error).
LoginProvider
| Property | Description | 
|---|---|
| apiTokensClientSettings | Optional. Settings for the Api tokens client. If omitted, the Api tokens clientis not created. | 
| debug | Optional. If true, debugging is enabled. See Oidc client settings. | 
| modules | Optional. An array of custom modules. | 
| sessionPollerSettings | Optional. Settings for the Session poller. If omitted, the Session polleris not created. If default values are acceptable, an empty object is required to create the poller. | 
| userManagerSettings | Required. The HDS Oidc client uses oidc-client-ts to handle redirect URLs, token parsing and expiration. Both use the same userManagerSettings, but different defaults. | 
SessionEndedHandler
| Property | Description | 
|---|---|
| content | Required. Textual content with properties title,text,buttonTextandcloseButtonLabelText. | 
| dialogProps | Optional. Additional DialogProps passed to the Dialog. | 
| ids | Optional. Ids for the dialog elements with properties dialog,title, andtext. If omitted, ids are created. | 
WithAuthentication
| Property | Description | 
|---|---|
| AuthorisedComponent | Optional. Component to render if the user is authenticated. The user object is passed to the component. | 
| UnauthorisedComponent | Optional. Component to render if the user is not authenticated. | 
WithAuthenticatedUser
| Property | Description | 
|---|---|
| children | React children. A user object is passed to each child. | 
WithoutAuthenticatedUser
| Property | Description | 
|---|---|
| children | React children. | 
Modules
Usually, just logging in is not enough. The user must be able to fetch data from backend servers. That cannot be done unless the user's access token is exchanged for API tokens. Api tokens are sent in the headers of backend requests to authenticate the user.
HDS Login modules include also API token handling. It is an independent module, but it communicates with the Oidc client and updates automatically when the user logs in or is updated. The modules emit signals that can be listened to and reacted to.
There are four modules to handle the user's needs:
- Oidc client for user data.
- Api tokens client for acquiring backend tokens.
- ApolloClient module to provide the client and auto-append api tokens to queries.
- GraphQL module for fetching data from a graphQL server. Fetching can be automatically linked to
- TokenizedFetch module for fetching data from a server. Requests are automatically linked to the Api Tokens client.
All modules can be used without React and without each other. But a >user object is required to get API tokens and poll the session.
Oidc client
The Oidc client uses the oidc-client-ts and has the same settings but different defaults.
Settings
| Property | Default value | 
|---|---|
| debug | Optional. If true, debugging is enabled in the oidc-client-ts instance with Log.setLevel(Log.Debug)andLog.setLogger(console). | 
| userManagerSettings | Required, but not all options. At least authority,client_idandscopemust be set. | 
Default userManager settings
| Property | Default value | 
|---|---|
| automaticSilentRenew | true | 
| includeIdTokenInSilentRenew | true | 
| loadUserInfo | true | 
| monitorSession | false | 
| post_logout_redirect_uri | window.origin + / | 
| redirect_uri | window.origin + /callback | 
| response_type | code | 
| silent_redirect_uri | window.origin + /silent_renew.html | 
| validateSubOnSilentRenew | false | 
These override the default settings of the oidc-client-ts.
Methods
| Property | Description | Return value | 
|---|---|---|
| getAmr | Returns the user's amrvalue(s) as an array. Tunnistamo returns theamras a string, which oidc-client-ts rejects because it violates the OIDC specification. Then theamrvalue is read from the decryptedid_token. | Amrorundefined | 
| getState | State of the client. See Oidc client states. | State | 
| getToken | Returns a token. The function is async because token renewal might be in progress and the current token might be outdated after that. If renewal was in progress but failed, then the old token is returned. Use isRenewing()and the exported functiongetUserToken(user, tokenType)to get the token synchronously and safely. The Promise will never be rejected. | stringorundefined | 
| getUser | Returns a user object or null. | User or null | 
| getUserManager | Returns the UserManager. | UserManager | 
| handleCallback | Handles the callback data and returns a user object - if the user is valid. | Promise<User>orPromise<OidcClientError> | 
| isAuthenticated | Returns true if the user exists and the user object passes isValidUser()check. | boolean | 
| isRenewing | Returns true if the user renewal is in progress. | boolean | 
| login | Calls the authorization_endpointwith given parameters. The browser window is redirected and the returned promise is fulfilled only, if an error occurs when redirecting. Parameters are documented in the UserManager.signinRedirect of the oidc-client-ts. Used language can be set with a customlanguageprop. | Promise<never> | 
| logout | Calls the end_session_endpointwith given parameters. The browser window is redirected so the returned promise is never fulfilled. Parameters are documented in the UserManager.signoutRedirect of the oidc-client-ts. Used language can be set with a customlanguageprop. | Promise<never> | 
| renewUser | For manual user renewal. The Promise will never be rejected. | Promise<User> | 
Other exported utility functions
The following functions can be imported and used without the Oidc client module:
| Function | Description | Argument(s) | Return value | 
|---|---|---|---|
| createOidcClient(props) | Creates the Oidc client. | Oidc clientprops. | OidcClient | 
| getUserStoreKey(settings) | Returns the session storage key for the user data. | UserManagerSettings object. | string | 
| getUserFromStorage(settings, storage) | Returns user data from storage. | UserManagerSettings object, storage to get the user from. (optional, default is session storage). | User or null | 
| isUserExpired(user) | Returns true if the user is expired. | User object. | boolean | 
| isValidUser(user) | Returns true if the user is not expired and has an access token. | User object. | boolean | 
| pickUserToken(user, tokenType) | Returns one of the user's tokens: access,idorrefresh. | User object, token type ( access,idorrefresh). | stringorundefined | 
import { isUserExpired } from 'hds-react';if (isUserExpired(user)) {// Show an error}
State change signals
When the user does something, the Oidc client's state changes and the UI can indicate it by reacting to the state change signals. The simplest way to react to signals is useOidcClientTracking hook.
The current state can also be read with oidcClient.getState().
There are utility functions for each state change. Use these to check if the emitted signal contains that state.
| State | Description | Utility function to check the signal | 
|---|---|---|
| HANDLING_LOGIN_CALLBACK | The browser has returned from an Oidc provider and data is being parsed. | isHandlingLoginCallbackSignal(signal) | 
| LOGGING_IN | State changes to this when login()is called. | isLoggingInSignal(signal) | 
| LOGGING_OUT | State changes to this when logout()is called. | isLoggingOutSignal(signal) | 
| NO_SESSION | No valid user exists. | isNoSessionSignal(signal) | 
| VALID_SESSION | User is found and is valid. | isValidSessionSignal(signal) | 
Error signal types
Errors are rarely thrown; they are emitted as error signals where the error object is in the signal payload. Errors are instances of the OidcClientError. It is an extended Error object with a type property and multiple .is... getters for checking error types.
The error object also contains the thrown error in error.originalError property.
| Error type | Description | Error object property to check | Utility function to check the signal | 
|---|---|---|---|
| INVALID_OR_EXPIRED_USER | The returned user object is expired or invalid. | error.isInvalidUserError | isInvalidUserErrorSignal(signal)  | 
| RENEWAL_FAILED | User renewal failed. | error.isRenewalError | isRenewalErrorSignal(signal) | 
| SIGNIN_ERROR | Emitted when handleCallback()orlogin()failed. | error.isSignInError | isSigninErroSignal(signal)  | 
Event signals
The Oidc client also emits event signals when an action is complete or starting. The difference between state changes and events is the UI does not usually need to react to events.
| Event type | Description | Utility function to check the signal | 
|---|---|---|
| USER_UPDATED | User data has changed. Includes also changes to null, if login or renewal fail. | isUserUpdatedSignal(signal)  | 
| USER_REMOVED | User data was removed. Happens when the user logs out or tokens expire. | isUserRemovedSignal(signal)  | 
| USER_RENEWAL_STARTED | User is being renewed. Current access_token and API tokens may be invalid until the renewal is complete. | isUserRenewalStartedSignal(signal)  | 
Dedicated signal triggers
Generic triggers for Oidc client signals. These trigger only if the signal originated from the Oidc client.
| Generic triggers | Required signal props to trigger the listener | 
|---|---|
| triggerForAllOidcClientErrors | Oidc clientnamespace and typeerror. | 
| triggerForAllOidcClientEvents | Oidc clientnamespace and typeevent. | 
| triggerForAllOidcClientSignals | Oidc clientnamespace. | 
| triggerForAllOidcClientStateChanges | Oidc clientnamespace and typestateChange. | 
State change triggers require the signal to have the Oidc client namespace and type stateChange.
Signal.payload.type must contain one of the states.
| State change triggers | Required signal props to trigger the listener | 
|---|---|
| loggingInTrigger | payload.typehas a matching state. | 
| loggingOutTrigger | payload.typehas a matching state. | 
| noSessionTrigger | payload.typehas a matching state. | 
| validSessionTrigger | payload.typehas a matching state. | 
Event triggers require the signal to have the Oidc client namespace and type event.
Signal.payload.type contains one of the events.
| Event triggers | Required signal props to trigger the listener | 
|---|---|
| userRemovedTrigger | payload.typehas a matching event. | 
| userRenewalStartedTrigger | payload.typehas a matching event. | 
| userUpdatedTrigger | payload.typehas a matching event. | 
Error triggers require the signal to have the Oidc client namespace and type error.
Signal.payload.type contains one of the errors.
| Error triggers | Required signal props to trigger the listener | 
|---|---|
| invalidUserErrorTrigger | payload.typehas a matching error. | 
| renewalErrorTrigger | payload.typehas a matching error. | 
| signInErrorTrigger | payload.typehas a matching error. | 
Getting signal payloads
Sometimes the most significant part of a signal is the payload. There are predefined payload getters for the Oidc client.
If the given signal is not from Oidc client or is not of the given type, the function returns null. So there is no need to pre-check the signal namespace or type.
| Payload getter | Returns | 
|---|---|
| getOidcClientEventPayload | nullor{type, data}. The data is usually a user object. | 
| getOidcClientErrorPayload | nullor OidcClientError object. | 
| getOidcClientStateChangePayload | nullor{state, previousState}. | 
Hooks
Oidc client hooks are listed in the hooks section.
Api tokens client
The Api tokens client listens to the Oidc client signals and waits until the user is authenticated and then fetches the API tokens. It retries if fetch fails and terminates when the maximum number of retries is reached.
When the user is about to expire and renews, API tokens are also renewed automatically.
When user renewal starts, API tokens are also removed to prevent usage of API tokens that are not possibly valid anymore. Use isRenewing() to check if API tokens are being renewed, and if it returns 'false', then use the API tokens returned by getTokens().
Requirements
URL where to get the tokens from. A user's access token is also required, so the user must be authenticated to fetch API tokens.
Settings
| Property | Description | Default value | 
|---|---|---|
| audiences | Optional. An array of strings. Used with Helsinki Profile api token requests. One token is fetched for each audience. | none | 
| maxRetries | Optional. The number of max retries until fetching is stopped. | 4 | 
| queryProps | Optional. An object. Used with Helsinki Profile api token requests. Contains properties grantTypeandpermission. | none | 
| retryInterval | Optional. Waiting time in milliseconds between failed requests. | 500 | 
| url | Required. URL to the API tokens endpoint. | none | 
Methods
| Property | Description | Return value | 
|---|---|---|
| clear | Cancels fetch and removes all data. | none | 
| fetch | Fetches the tokens from the given URI. | Promise<Tokens> | 
| getTokens | Gets locally stored tokens. | Tokens | 
| isRenewing | Returns true if tokens are currently fetched. | boolean | 
Api Token Client Tracker utility
Multiple modules need to track api tokens and their renewal process. This util listens to changes and also times out when the renewal is taking too long.
| Name | Description | Default value | 
|---|---|---|
| keepTokensAfterRenewalError | If renewal fails, should old tokens be kept of not. | false | 
| keepTokensWhileRenewing | If true, the stored api tokens are not cleared when renewal starts. | true | 
| onChange(tokens: TokenData, changeTrigger: Signal) | Called when api tokens change. Not called when dispose() is called. Second argument is the signal that caused the change. | - | 
| rejectionSignalTrigger | Type of the signal that should end the pending api token renewal promise. Usually it is a clear/dispose signal from the module using this util, so the promise is fulfilled when the module is not used anymore. | - | 
| timeout | How long to wait for apitoken renewal to fulfill. | 15000 | 
The function returns an object with following properties
| Property | Arguments | Return values | 
|---|---|---|
| connect(connectedBeacon: Beacon) | Connect the utility to a beacon. | void | 
| dispose() | Dispose listeners, references and data. | void | 
| getTokens() | Get current tokens. | TokenData(empty object, if no existing tokens) | 
| isRenewing() | Returns true, if renewal process is on-going. | boolean | 
| stopWaitingForTokens() | Discards pending promise for api token renewal. Emits signal to abort it. Same signal is used in all instance of this utility, so the signal stops them all. | void | 
| waitForApiTokens() | Returns the pending renewal promise or immediately resolved promise. Never rejects, the returned boolean indicates was the promise successful. | Promise<boolean> | 
Other exported utility functions
The following functions can be imported and used without the Api tokens client module:
| Function | Description | Argument(s) | Return value | 
|---|---|---|---|
| createApiTokenClient(props) | Creates the client. | ApiTokenClientProps. | ApiTokensClient | 
| getApiTokensFromStorage(storage) | Gets the API tokens from session storage. | Storage to get the tokens from. (optional, default is session storage). | TokenData or null | 
| getUserReferenceFromStorage(storage) | Gets the user's access token used as reference. | Storage to get the reference from. (optional, default is session storage). | string | 
| removeApiTokensFromStorage(storage) | Removes the API tokens from session storage. | Storage to remove the tokens from. (optional, default is session storage). | none | 
| removeUserReferenceFromStorage(storage) | Removes the user's access token used as reference. | Storage to remove the reference from. (optional, default is session storage). | none | 
| setApiTokensToStorage(tokens, storage) | Sets the API tokens to storage. | Tokens, storage to set the tokens to. (optional, default is session storage). | none | 
| setUserReferenceToStorage(reference,storage) | Sets the user's access token used as reference. | Reference as string, tokens, storage to set the tokens to. (optional, default is session storage). | none | 
import { getApiTokensFromStorage } from 'hds-react';const apiTokens = getApiTokensFromStorage();if (apiTokens) {// Use tokens}
State change signals
The Api tokens client has no state changes.
Error signal types
Returned errors are instances of the ApiTokensClientError. It is an extended Error object with type property and multiple .is... getters for checking error types. The error object also contains the thrown error in error.originalError property.
| Error type | Description | Error object property to check | Utility function to check the signal | 
|---|---|---|---|
| API_TOKEN_FETCH_FAILED | Fetch failed. | error.isFetchError | isApiTokensFetchFailedErrorSignal(signal) | 
| INVALID_API_TOKENS | The returned object is an invalid json. | error.isInvalidTokensError | isInvalidApiTokensErrorSignal(signal) | 
| INVALID_USER_FOR_API_TOKENS | User is not valid. | error.isInvalidApiTokensUserError | isInvalidApiTokensUserErrorSignal(signal) | 
Event signals
The Api tokens client also emits events when an action is complete or starting.
| Event type | Description | Utility function to check the signal | 
|---|---|---|
| API_TOKENS_UPDATED | Tokens have changed. Includes also changes to null. | isApiTokensUpdatedSignal(signal) | 
| API_TOKENS_REMOVED | Tokens have been removed. Happens usually when the user object has been removed or is renewed. | isApiTokensRemovedSignal(signal) | 
| API_TOKENS_RENEWAL_STARTED | Api tokens are renewed. Happens usually right after user renewal. | isApiTokensRenewalStartedSignal(signal) | 
Dedicated signal triggers
Triggers for Api tokens client signals. These trigger signals only originated from the Api tokens client.
| Generic triggers | Required signal props to trigger the listener | 
|---|---|
| triggerForAllApiTokensClientErrors | Api tokens clientnamespace and typeerror. | 
| triggerForAllApiTokensClientEvents | Api tokens clientnamespace and typeevent. | 
| triggerForAllApiTokensClientSignals | Api tokens clientnamespace. | 
Event triggers require the signal to have Api tokens client namespace and type event.
Signal.payload.type contains one of the events.
| Event triggers | Required signal props to trigger the listener | 
|---|---|
| apiTokensRemovedTrigger | payload.typehas a matching event. | 
| apiTokensRenewalStartedTrigger | payload.typehas a matching event. | 
| apiTokensUpdatedTrigger | payload.typehas a matching event. | 
Error triggers require the signal to have Api tokens client namespace and type error.
Signal.payload.type contains one of the errors.
| Error triggers | Required signal props to trigger the listener | 
|---|---|
| apiTokensFetchFailedErrorTrigger | payload.typehas a matching error. | 
| invalidApiTokensErrorTrigger | payload.typehas a matching error. | 
| invalidApiTokensUserErrorTrigger | payload.typehas a matching error. | 
Getting signal payloads
Sometimes the most significant part of a signal is the payload. There are predefined payload getters for the Api tokens client.
If the given signal is not from Api tokens client or is not given type, the function returns null. So there is no need to pre-check the signal namespace or type.
| Payload getter | Returns | 
|---|---|
| getApiTokensClientErrorPayload | nullor ApiTokensClientError object. | 
| getApiTokensClientEventPayload | nullor{type, data}. The data is usually tokens. | 
Hooks
Api tokens client hooks are listed in the hooks section.
Session poller
The user's session could end outside of the current browser window. The Session poller calls the userinfo endpoint and notifies when it receives an unauthorized or forbidden response.
Successes and other errors are ignored.
Requirements
Polling requires a user and the userManager from the Oidc client. The polling endpoint is fetched from userManager's metadata.
Settings
| Property | Description | Default value | 
|---|---|---|
| pollIntervalInMs | Optional. Waiting time between polls in milliseconds. The default is one minute. | 60000 | 
Methods
| Property | Description | Return value | 
|---|---|---|
| start | Starts the polling. The first check is done after pollIntervalInMs is expired. Not immediately. | |
| stop | Stops the polling and aborts current requests, if any. | Tokens | 
Other exported utility functions
The following function can be imported and used without the Session poller module:
| Property | Description | Argument(s) | Return value | 
|---|---|---|---|
| createSessionPoller(options) | Creates the poller. | SessionPollerOptions. | SessionPoller | 
import { createSessionPoller } from 'hds-react';const sessionPoller = createSessionPoller();
State change signals
The Session poller has no state changes.
Error signal types
Returned errors are instances of the SessionPollerError. It is an extended Error object with type property and multiple .is... getters for checking error types. The error object also contains the thrown error in error.originalError property.
| Error type | Description | Error object property to check | Utility function to check the signal | 
|---|---|---|---|
| SESSION_ENDED | The server returned a forbidden or unauthorized status code. | error.isSessionEnded | isSessionEndedSignal(signal)  | 
| SESSION_POLLING_FAILED | Polling has failed and max retries have been reached. | error.isSessionPollingFailure | isSessionPollingFailureSignal(signal) | 
Event signals
The Session poller also emits events when an action is complete or starting.
| Event type | Description | Utility function to check the signal | 
|---|---|---|
| SESSION_POLLING_STARTED | Polling has started. | isSessionPollerStartedSignal(signal) | 
| SESSION_POLLING_STOPPED | Polling has stopped. | isSessionPollerStoppedSignal(signal) | 
Dedicated signal triggers
Triggers for Session pollersignals. These trigger signals only originated from the Session poller.
| Generic triggers | Required signal props to trigger the listener | 
|---|---|
| triggerForAllSessionPollerErrors | Session pollernamespace and typeerror. | 
| triggerForAllSessionPollerEvents | Session pollernamespace and typeevent. | 
| triggerForAllSessionPollerSignals | Session pollernamespace. | 
Event triggers require the signal to have a Session poller namespace and type event.
Signal.payload.type contains one of the events.
| Event triggers | Required signal props to trigger the listener | 
|---|---|
| sessionPollingStartedTrigger | payload.typehas a matching event. | 
| sessionPollingStoppedTrigger | payload.typehas a matching event. | 
Error triggers require the signal to have a Session pollernamespace and type error.
Signal.payload.type contains one of the errors.
| Error triggers | Required signal props to trigger the listener | 
|---|---|
| sessionEndedTrigger | payload.typehas a matching error. | 
| sessionPollingFailedTrigger | payload.typehas a matching error. | 
Getting signal payloads
Sometimes the most significant part of a signal is the payload. There are predefined payload getters for the Session poller.
If the given signal is not from the Session poller or is not given type, the function returns null. So there is no need to pre-check the signal namespace or type.
| Payload getter | Returns | 
|---|---|
| getSessionPollerErrorPayload | nullor SessionPollerError object. | 
| getSessionPollerEventPayload | nullor{type, data}. The data is usually tokens. | 
GraphQL Module
Loading data from a graphQL server may require user authentication and api tokens. The GraphQL module can be set to listen to the Api token client and start querying when api tokens are ready. It can pick the correct api token and set it to the query headers.
The module can also be used without api tokens and can be controlled manually.
Unlike the Api token client and Session Poller, the GraphQL Module must be manually added to the <LoginProvider>.
import { ApolloClient } from '@apollo/client';import { createGraphQLModule } from 'hds-react';import { queryDocument } from './<path to queries>';const graphQLClient = new ApolloClient({uri: 'https://graphql.endpoint.com/graphql/',cache: new InMemoryCache(),});const options = {graphQLClient,query: queryDocument,queryOptions: {errorPolicy: 'all',},};const graphQLModule = createGraphQLModule(options);<LoginProvider {...loginProps} modules={[graphQLModule]}></LoginProvider>;
Requirements
To execute a query, the following requirements must be met:
- A graphQLClient (ApolloClient) must be configured and passed to the GraphQL module.
- A query document must be provided.
If the graphQL end-point requires an authentication, then the authentication headers must be set by
- Providing them in queryOptions.header.
- Setting them in queryHelper().
- Requiring api tokens with options.requireApiTokensand settingoptions.apiTokenKey.
Important
The module props do not require a query document or a graphQLClient, but a query cannot be executed without them. Both can also be passed as arguments to the query(options). The client can also be set by calling setClient(client).
Once set, the client is stored, and there is no need to pass it again. The query document is not stored, so different queries can be used every time.
When used with Helsinki City Profile, the queryOptions.errorPolicy should be set to "all". Otherwise, queries will fail when a weakly authenticated user tries to get the profile. The resulting data will include (dismissable) errors, and an ApolloClient query will fail when the data has an error property.
The createGraphQLModule function is a Generic Typescript function with two types: createGraphQLModule<Q = GraphQLQueryResult, T = NormalizedCacheObject>. The first type, Q, defines what kind of results the query returns. The latter, T, only describes the cache type of the ApolloClient and is not usually changed.
Settings
| Property | Type | Description | Default value | 
|---|---|---|---|
| graphQLClient | ApolloClient | Optional property, but must be set before the query is executed. Can be set with setApolloClientor when calling aquery(options). The ApolloClient Module can also be used. | - | 
| query | TypedDocumentNode or DocumentNode | A graphQL query document. | - | 
| queryHelper | (currentOptions:QueryOptions, apiTokenClient?: ApiTokenClient, beacon?:Beacon) => QueryOptions | This function is called before a query is executed. The options object returned by the function is used as query options. | - | 
| options | object | GraphQL module options. | |
| options.autoFetch | boolean | Should query be executed automatically on initialization. | true | 
| options.requireApiTokens | boolean | Are api tokens required for queries. | true | 
| options.abortIfLoading | boolean | Should an on-going query be aborted when query()is called again. If false, thequery()will return a pending promise, and a new query is not started. | true | 
| options.keepOldResultOnError | boolean | Should old result be kept, if a newer query fails. | false | 
| options.apiTokensWaitTime | number | How long in milliseconds should api tokens be awaited before rejecting a query. | 15 000 | 
| options.apiTokenKey | string | An object key for the api token to use in a query. The token is picked with apiTokens[key]. | - | 
| queryOptions | QueryOptionsexcluding thequeryproperty | Other ApolloClient queryOptions except querydocument. | - | 
| useApolloClientModule | boolean | If true, ApolloClient is picked from modules. The ApolloClient Module must be created manually. | false | 
Methods
| Property | Description | Argument(s) | Return value | 
|---|---|---|---|
| cancel | Cancels current query. The pending query is aborted. | - | - | 
| clear | Calls cancel()and also clears errors and results. Emits a GRAPHQL_MODULE_CLEARED event. | - | - | 
| getClientErrors | Returns array of query errors and/or errors in the result data. | - | ApolloError[] | 
| getData | Returns the dataproperty of last successful query result. | - | The result.dataof latest query orundefined | 
| getError | Returns a query error. | - | ApolloErrororundefined | 
| getQueryPromise | Returns the current pending query promise or an immediately rejected promise. | - | Promise<ApolloQueryResult> | 
| getResult | Returns the latest query result. | - | ApolloQueryResultorundefined | 
| isLoading | Returns true if a query fetch is currently active. | - | boolean | 
| isPending | Returns true if the module is waiting for api tokens or query results. | - | boolean | 
| query | Executes a query. | Partial<GraphQLModuleModuleProps> | Promise<QueryResult> | 
| queryCache | Calls query(options)withfetchPolicy: 'cache-only'in options. | Partial<GraphQLModuleModuleProps> | Promise<QueryResult> | 
| queryServer | Calls query(options)withfetchPolicy: 'network-only'in options. | Partial<GraphQLModuleModuleProps> | Promise<QueryResult> | 
| setClient | Sets the graphQLClient. | ApolloClient | - | 
| waitForApiTokens | Returns a promise that is resolved when api tokens are found. | timeout?: number. Time in milliseconds when the Promise is rejected. If omitted, the promise will not timeout. | Promise<void> | 
Other exported utility functions
The following functions can be imported and used without the GraphQL module module:
| Function | Description | Argument(s) | Return value | 
|---|---|---|---|
| createGraphQLModule(options) | Creates the module. | GraphQLModuleModuleProps. | GraphQLModule | 
| mergeQueryOptionContexts(options, context) | Deep merges given context to queryOptions. | QueryOptions, QueryOptions['context'] | QueryOptions | 
| mergeHeadersToQueryOptions | Deep merges given headers to queryOptions.context. | QueryOptions, Record | QueryOptions | 
| mergeAuthorizationHeaderToQueryOptions | Sets authorization: <given header>toqueryOptions.context.headers. Typically the value isBearer: <token>. | QueryOptions, string | QueryOptions | 
| mergeQueryOptions | Deep merges given queryOptions to another queryOptions object | QueryOptions, QueryOptions | QueryOptions | 
| setBearerToQueryOptions | Shortcut for calling mergeAuthorizationHeaderToQueryOptions(options, 'Bearer: <token>'). | QueryOptions, string | QueryOptions | 
| appendFetchOptions | Appends fetchOptions to queryOptions.context. | QueryOptions, Partial<RequestInit> | QueryOptions | 
State change signals
The GraphQL module has no state changes.
Error signal types
Returned errors are instances of the GraphQLModuleError. It is an extended Error object with type property and multiple .is... getters for checking error types. The error object also contains the thrown error in error.originalError property.
| Error type | Description | Error object property to check | Utility function to check the signal | 
|---|---|---|---|
| GRAPHQL_LOAD_FAILED | Query failed. | error.isLoadError | isGraphQLModuleLoadFailedSignal(signal)  | 
| GRAPHQL_NO_CLIENT | Query failed, because client is not provided. | error.isNoClientError | isGraphQLModuleNoClientErrorSignal(signal)  | 
| GRAPHQL_NO_API_TOKENS | Api tokens are required, but not found or fetching them timed out. | error.isNoApiTokensError | isGraphQLModuleNoApiTokensErrorSignal(signal)  | 
Event signals
The GraphQL module also emits events when an action is complete or starting.
| Event type | Description | Utility function to check the signal | 
|---|---|---|
| GRAPHQL_MODULE_LOADING | Query has started. | isGraphQLModuleLoadingSignal(signal) | 
| GRAPHQL_MODULE_LOAD_SUCCESS | Query was successful. | isGraphQLModuleLoadSuccessSignal(signal) | 
| GRAPHQL_MODULE_LOAD_ABORTED | Query was aborted. | isGraphQLModuleLoadAbortedSignal(signal) | 
| GRAPHQL_MODULE_CLEARED | The module was cleared. | isGraphQLModuleClearedSignal(signal) | 
Dedicated signal triggers
Triggers for GraphQL modulesignals. These trigger signals only originated from the GraphQL module.
| Generic triggers | Required signal props to trigger the listener | 
|---|---|
| triggerForAllGraphQLModuleErrors | GraphQL modulenamespace and typeerror. | 
| triggerForAllGraphQLModuleEvents | GraphQL modulenamespace and typeevent. | 
| triggerForAllGraphQLModuleSignals | GraphQL modulenamespace. | 
Event triggers require the signal to have a GraphQL module namespace and type event.
Signal.payload.type contains one of the events.
| Event triggers | Required signal props to trigger the listener | 
|---|---|
| graphQLModuleClearedTrigger | payload.typehas a matching event. | 
| graphQLModuleLoadAbortedTrigger | payload.typehas a matching event. | 
| graphQLModuleLoadingTrigger | payload.typehas a matching event. | 
| graphQLModuleLoadSuccessTrigger | payload.typehas a matching event. | 
Error triggers require the signal to have a GraphQL modulenamespace and type error.
Signal.payload.type contains one of the errors.
| Error triggers | Required signal props to trigger the listener | 
|---|---|
| loadFailedErrorTrigger | payload.typehas a matching error. | 
| noApiTokensErrorTrigger | payload.typehas a matching error. | 
| noClientErrorTrigger | payload.typehas a matching error. | 
Getting signal payloads
Sometimes the most significant part of a signal is the payload. There are predefined payload getters for the GraphQL module.
If the given signal is not from the GraphQL module or is not given type, the function returns null. So there is no need to pre-check the signal namespace or type.
| Payload getter | Returns | 
|---|---|
| getGraphQLModuleErrorPayload | nullor GraphQLModuleError object. | 
| getGraphQLModuleEventPayload | nullor{type, data}. | 
ApolloClient Module
Appending api tokens to every query and manually waiting for api token renewal is a complicated task. The ApolloClient module links itself to the Api token client and automatically appends tokens and also awaits for token renewals.
The module can also be used without api tokens. This module does not emit signals.
The ApolloClient Module must be manually added to the <LoginProvider>. Preferably use the LoginProviderWithApolloContext which also creates the ApolloContext.
import { createApolloClientModule } from 'hds-react';const options = {clientOptions:{// apollo client option.},tokenSetter: (headers, apiTokens) => {return {Authentication: apiTokens['tokenToAppend'],};},};const apolloClientModule = createApolloClientModule(options);<LoginProviderWithApolloContext {...loginProps} modules={[apolloClientModule]}></LoginProviderWithApolloContextx >;
The createApolloClientModule function is a Generic Typescript function: createApolloClientModule<T = InMemoryCache>. The generic describes the cache type of the ApolloClient and is not usually changed.
Settings
| Property | Type | Description | Default value | 
|---|---|---|---|
| apiTokensWaitTime | number | How long in milliseconds should api tokens be awaited before stopping the wait time. This will never reject any queries even if timeout is reached. | 15000 | 
| clientOptions | Partial<ApolloClientOptions> | Options for the ApolloClient. If "uri" option is given, a HttpLink is automatically created from it. The module adds its own AplloLink(s) before other links. | - | 
| keepTokensWhileRenewing | boolean | If true, the stored api tokens are not cleared when renewal starts. | true | 
| preventQueriesWhileRenewing | boolean | If true, a ApolloLink is added to wait for possible api token renewal to end. If false, there might be times when queries are made with old api tokens. Unlikely, but possible. | true | 
| tokenSetter | (headers:unknown,tokens:TokenData)=> Record<string,string> | The returned object is appended to the headers. First argument type depends on the request. Can be an object or Headers. | - | 
Methods
| Property | Description | Argument(s) | Return value | 
|---|---|---|---|
| getClient | Returns the ApolloClient. | - | ApolloClient | 
| getTracker | Returns the apiTokenClient tracker. | - | ApiTokenTracker | 
| reset | Resets the client and apiTokenTracker | - | Promise<void> | 
The ApolloClient does not emit any signals. Therefore there are no hooks or triggers related to signals.
TokenizedFetch Module
Loading data from a server may require user authentication and api tokens. The TokenizedFetch module listens to the Api token client and appends api tokens to the request headers.
The TokenizedFetch Module must be manually added to the <LoginProvider>.
import { createTokenizedFetchModule } from 'hds-react';const options = {tokenSetter: (headers, apiTokens) => {return {Authentication: apiTokens['tokenToAppend'],};},};const tokenizedFetchModule = createTokenizedFetchModule(options);<LoginProvider {...loginProps} modules={[tokenizedFetchModule]}></LoginProvider>;
Settings
| Property | Type | Description | Default value | 
|---|---|---|---|
| preventQueriesWhileRenewing | string | If true, a ApolloLink is added to wait for possible api token renewal to end. If false, there might be times when queries are made with old api tokens. Unlikely, but possible. | true | 
| tokenSetter | (headers:unknown, tokens:TokenData) => Record<string,string> | The returned object is appended to the headers. First argument type depends on the request. Can be an object or Headers. | - | 
Methods
| Property | Description | Argument(s) | Return value | 
|---|---|---|---|
| tokenizedFetch | Proxy to the native fetchfunction. Headers returned from the optionaltokenSetterare appended to the Headers passed as args. | Same as native fetch. | Same as native fetch. | 
| tokenizedFetchWithSignals | Calls the tokenizedFetch, but also emits start and end signals. If fetch fails, an error signal is emitted. Aborted requests are emitted as event signals. Abort and start signals can be distinguished from actual responses with isTokenizedFetchStartedSignal(signal)andisTokenizedFetchAbortedSignal(signal). Automatic response handling uses theresponse.json()to parse response from data. If the data is not json, do not use automation and this function. UseemitResponse(promise.then(<your parse function>)). | - | - | 
| getTracker | Returns the apiTokenClient tracker. | - | - | 
| reset | Emits reset signal and resets the apiTokenTracker. | - | - | 
| isAbortError | Utility to test was the returned error an AbortError. | - | - | 
| emitResponse | The promise returned from tokenizedFetch can be passed to this function which will emit the results as event signals or error signals. | - | - | 
| emitFetchStart | Emits a signal where payload.type = ${responseSignalType}\_STARTED. | - | - | 
| addAbortSignal | Adds abort signal to FetchInit props and returns a function that will abort the request. | - | - | 
Other exported utility functions
The following functions can be imported and used without the TokenizedFetch module module:
| Function | Description | Argument(s) | Return value | 
|---|---|---|---|
| createTokenizedFetchModule(options) | Creates the module. | TokenizedFetchModuleProps | TokenizedFetchModule | 
| isTokenizedFetchStartedSignal(signal) | Returns true if the signal was emitted to indicate fetch start. | Signal | boolean | 
| isTokenizedFetchAbortedSignal(signal) | Returns true if the signal was emitted to indicate fetch abort. | Signal | boolean | 
State change signals
The TokenizedFetch module has no state changes.
Error signal
The module emits only one kind of error. They are instances of the TokenizedFetchModuleError. It is an extended Error object with type property and a hasResponseIdentifierMatch helper function to identify fetch calls. The error object also contains the thrown error in error.originalError property.
The hasResponseIdentifierMatch(type:string)=>boolean returns true if the error originated from a fetch with given id. Ids are used only when using tokenizedFetchWithSignals or emitResponse.
Event signals
The TokenizedFetch module also emits events only when the tokenizedFetchWithSignals is used. Events can also be manually emitted with emitFetchStart or emitResponse
The simplest way to track signals is with hooks.
Dedicated signal triggers
Triggers for TokenizedFetch module signals. These trigger signals only originated from the TokenizedFetch module.
| Generic triggers | Required signal props to trigger the listener | 
|---|---|
| triggerForAllTokenizedFetchErrors | TokenizedFetch modulenamespace and typeerror. | 
| triggerForAllTokenizedFetchEvents | TokenizedFetch modulenamespace and typeevent. | 
| triggerForAllTokenizedFetchSignals | TokenizedFetch modulenamespace. | 
The createTriggerPropsForTokenizedFetchResponseSignals(identifier: string): SignalTrigger creates a SignalTrigger that returns true if the signal is an event signal from the TokenizedFetch Module and its payload has given identifier.
Getting signal payloads
Sometimes the most significant part of a signal is the payload. There are predefined payload getters for the TokenizedFetch module.
If the given signal is not from the TokenizedFetch module or is not given type, the function returns null. So there is no need to pre-check the signal namespace or type.
| Payload getter | Returns | 
|---|---|
| getTokenizedFetchModuleEventPayload | nullorEventPayload. The payload may be aResponseor information aboutstartorabortsignals. | 
| getTokenizedFetchModuleErrorPayload | nullorError. | 
| getTokenizedFetchPayloadData | nullor the actual serverResponse. | 
Oidc client hooks
| Hook | Description | Return value | 
|---|---|---|
| useAuthenticatedUser | Returns a user object, if it is valid and authenticated and passes isValidUser() check. | User or null | 
| useCachedAmr | Returns the user's amrvalue. It is cached because in some cases it must be decrypted fromid_token. | string[] | 
| useOidcClient | Returns the Oidc client. | OidcClient | 
| useOidcClientTracking | Returns an array of [Signal, resetFunction, oidcClient instance]. The hook forces the component using it to re-render each time the listener is triggered. | [Signal or undefined, ()=>void, OidcClient] | 
The usage of the Oidc client hooks is described in the usage section.
Api tokens client hooks
| Hook | Description | Return value | 
|---|---|---|
| useApiTokens | Returns functions for checking tokens and the status of renewal. | {getStoredApiTokens(), isRenewing()} | 
| useApiTokensClient | Returns the Api tokens client. | ApiTokensClient | 
| useApiTokensClientTracking | Returns an array of [Signal, resetFunction, apiTokensClient instance]. The hook forces the component using it to re-render each time the listener is triggered. | [Signal or undefined, ()=>void, ApiTokensClient] | 
The usage of the Api tokens client hooks is described in the usage section.
Session poller hooks
| Hook | Description | Return value | 
|---|---|---|
| useSessionPoller | Returns the Session poller. | SessionPoller | 
| useSessionPollerTracking | Returns an array of [Signal, resetFunction, sessionPoller instance]. The hook forces the component using it to re-render each time the listener is triggered. | [Signal or undefined, ()=>void, SessionPoller] | 
The usage of the Session poller hooks is described in the usage section.
GraphQL module hooks
| Hook | Description | Return value | 
|---|---|---|
| useGraphQLModule | Returns the GraphQL module. | GraphQLModule | 
| useGraphQLModuleTracking | Returns [Signal, resetFunction, GraphQL module instance]. The hook forces the component using it to re-render each time the listener is triggered. | [signal, reset function, GraphQL module instance] | 
| useGraphQL | Mimics the useLazyQuery hook of the Apollo GraphQL library. The hook forces the component using it to re-render each time the module emits a signal. | [query, {data, error, loading, refetch}] | 
The usage of the GraphQL module hooks is described in the usage section.
ApolloClient module hooks
| Hook | Description | Return value | 
|---|---|---|
| useApolloClientModule | Returns the ApolloClient module. | ApolloClientModule | 
| useApolloClient | Returns the created ApolloClient. | ApolloClient | 
The usage of the ApolloClient module hooks is described in the usage section.
TokenizedFetch module hooks
| Hook | Description | Return value | 
|---|---|---|
| useTokenizedFetchModule | Returns the TokenizedFetch module. | TokenizedFetch | 
| useTokenizedFetch | Returns a function identical to the native fetchfunction.. | The native fetchfunction | 
| useTokenizedFetchModuleTracking | Returns [Signal, resetFunction, TokenizedFetch module instance]. The hook forces the component using it to re-render each time the listener is triggered. | [signal, reset function, TokenizedFetch module instance] | 
| useTokenizedFetchWithSignals | This hook works just like the useTokenizedFetchexcept it emits signals so individual fetches can be tracked. | Promise<Response> | 
| useTokenizedFetchResponseTracking | This hook works just like the useTokenizedFetchModuleTrackingexcept it tracks only signals emitted by the module and with given identifier. | Signal | 
Generic signal hooks
| Hook | Arguments | Return value | 
|---|---|---|
| useSignalListener(listener) | The listener function. There are no trigger props. The listener is always called when any signal is emitted in any namespace. The listener should return trueif the component should re-render. | An array of [Signal or undefined, ()=>void]. Latter is a reset function that clears the signal and re-renders the component. | 
| useSignalTrackingWithCallback(triggerProps, callback) | Signal props need to match the incoming signal to trigger the callback function. The hook never causes a re-render. The callback must do it. | none | 
| useSignalTrackingWithReturnValue(triggerProps) | Signal props need to match the incoming signal to trigger re-rendering. The hook creates a trigger from the props and re-renders if the trigger returns true. | Same as above. | 
Important! The listener passed to useSignalListener must be memoized or the hook will attach a new listener on each render because the props changed. The old one is disposed of but to avoid unnecessary listeners, use memoization with useMemo or useCallback. Note that all triggerFor... functions are constants and do not need memoization.
useSignalTrackingWithReturnValue and useSignalListener store their arguments in React refs, so memoization is not needed.
The usage of the signal hooks is described in the usage section.
Beacon
The beacon is the controller of all signals and listeners. It emits all signals and connects all modules. It also stores all modules.
Modules are added and connected by calling beacon.addContext(module). The beacon then calls module.connect() with the beacon as the only argument. After that, the module can listen to and emit signals.
Beacon methods
| Name | Arguments | Return values | 
|---|---|---|
| addListener(signalProps, trigger) | Signal props that trigger the listener or ready-made trigger function. | Disposer function that removes the listener. | 
| addSignalContext(module) | Adds a module and its context. The connectmethod of the added module is called immediately. | Disposer function to remove context. | 
| clear() | Removes all data. | none | 
| emit(signal) | A signal to emit. | none | 
| getAllSignalContextsAsObject() | Returns all stored contexts as on object of {[context.namespace]:context}. | Object | 
| getSignalContext(module) | Returns context for the given namespace. | Context module or undefined. | 
Important
Like in React, once a signal (an event in React) is emitted, it is destroyed after all listeners have been called. Copy the object if it is needed for later use.
Signals
Signals have a type property to separate, for example errors, from other signals. Signals are easier to create with utility functions than by manually setting all properties.
The signal object
A signal is an object with the following properties:
| Property | Description | Value type | 
|---|---|---|
| context | Optional. The emitting module instance. For example an Oidc clientinstance. This is not required, but if missing, the beacon will set it by finding the context withsignal.namespace. | object | 
| namespace | Required. The namespace is the name of the module that emitted the signal. | string | 
| payload | Optional. The payload contains metadata. For example type of the event. A payload can also be an Error object. | unknown | 
| type | Required. Type of the signal. Can be any string, but HDS emits init,error,eventandstateChangesignals. | string | 
Signal types and payloads
| Signal type | Importable variable | Payload | 
|---|---|---|
| error | errorSignalType | Payload is an error object. This way payload.typematcheserror.type. | 
| event | eventSignalType | Usually {type:event type}indicating what kind of event is emitted. May also havedataproperty containing for example User or Tokens. | 
| init | initSignalType | Emitted when all modules are connected and everything is ready. Emitted only once. Note that modules may emit other signals before this. | 
| stateChange | stateChangeSignalType | {state, previousState}New state and the previous state, if any. | 
Custom modules may emit any other kind of signal with different payloads.
Emitting signals
Only custom modules can emit signals. See the custom module documentation.
See also custom namespaced beacons.
Important
If a listener is added while signaling and it is triggered by the currently emitted signal, a loop could be created. This could occur when using hooks and not memoizing listeners. Avoid emitting signals inside listeners.
Listening to signals
A signal listener is a function that receives one argument: the signal. A listener can listen to all signals or just one type of signal with a certain namespace. Listeners can be even more specific and listen to signals with certain payloads. In short, a listener can listen to any properties of the signal and is triggered when all properties match.
The listener is called only if the emitted signal matches the given props.
For example, if the trigger props (the first argument) passed to beacon.addListener(trigger, listener) is { type:'error' }, the listener (second argument) is called when the emitted signal has a matching type. It does not matter what other props the signal has.
If the trigger props are { namespace:'myModule', payload:{ type: 'click' } }, the emitted signal must have those properties with the same, exact values. Other properties are not checked.
The trigger can also be a function. Internally all triggers are converted to functions.
Instead of writing signal types as strings, it is better to use predefined triggers:
- Oidc client triggers.
- Api tokens client triggers.
- Session poller triggers.
- GraphQL module triggers.
- TokenizedFetch module triggers.
- Generic triggers.
Generic triggers
Generic create... functions create trigger functions from given props. Creator functions are not objects, so they can be used to create triggers for multiple namespaces, payloads and so on.
| Trigger creator | Arguments | Default | 
|---|---|---|
| createInitTriggerProps(namespace) | Namespace to listen to. Listens only to initsignals. | all namespaces | 
| createErrorTriggerProps(namespace,type) | Namespace and payload.type to listen to. Listens only to errorsignals. | all namespaces | 
| createEventTriggerProps(namespace,type) | Namespace and payload.type to listen to. Listens only to eventsignals. | all namespaces | 
| createStateChangeTriggerProps(namespace, state, previousState) | Namespace to listen to. Given state and previousState must also match. Both are optional. | all namespaces | 
| createTriggerForAllNamespaces() | Listens to all signals in any namespace. | none | 
| createTriggerPropsForAllSignals(namespace) | Namespace to listen to. If omitted listens to all signals. | all namespaces | 
See also hooks.
Generic signal utility functions
Create
Signals are easier to create with functions than by manually setting all properties.
| Function | Description | 
|---|---|
| createErrorSignal(namespace, payload) | Creates an error signal with the given namespace and error payload. | 
| createEventSignal(namespace, payload) | Creates an event signal with the given namespace and event payload. | 
| createStateChangeSignal(namespace, state, previousState) | Creates a stateChangesignal with the given namespace andstateChangepayload. | 
Check
Check the signal type or namespace with these utilities.
| Function | Description | 
|---|---|
| isInitSignal(signal) | Returns true if the given signal is an init signal. | 
| isErrorSignal(signal) | Returns true if the given signal is an error signal. | 
| isEventSignal(signal) | Returns true if the given signal is an event signal. | 
| isNamespacedSignal(signal, namespace) | Returns true if the given signal has given namespace. | 
| isStateChangeSignal(signal) | Returns true if the given signal is a stateChangesignal. | 
Get payloads
Returns signal payload if the signal type is a match.
| Function | Description | 
|---|---|
| getErrorSignalPayload(signal) | Returns the payload if the given signal is an error signal. | 
| getEventSignalPayload(signal) | Returns true if the given signal is an event signal. | 
| getStateChangeSignalPayload(signal) | Returns true if the given signal is a stateChangesignal. | 
Convert and filter
| Function | Description | 
|---|---|
| convertSignalToTrigger(signal) | Removes the contextfrom the signal if the property exists. The given signal is not mutated. | 
| filterSignals(arrayOfSignals, matchingProps) | Filters signals from the array. Returns signals which match given props. | 
waitForSignals
The function returns a promise, which is resolved when the given signal(s) have been detected. Or it rejects the promise when a signal from an optional rejection list is given.
The function can be used for racing conditions, for example waiting for a user renewal success or error, whichever comes first.
Or wait for a longer set of emitted signals from the start of user renewal to the end of API token renewal.
The promise is created with waitForSignals(beaconInstance, arrayOfTriggers, options).
When the promise is resolved, it returns an array of received signals. If it is rejected, an error is returned.
| Argument | Type | Description | Default | 
|---|---|---|---|
| arrayOfTriggers | Object[] | Array of signals/signal props to match. Each array signal is checked once and removed when it matches. | none | 
| beaconInstance | Beacon | Beacon instance where listeners are added. | none | 
| options | Object  | Optional. | none | 
| options.allowSkipping | boolean | If true, and triggers are in order A, B, C, D and signal "C" is received. "A", "B", "C" are all removed from the array and are not checked again. | true | 
| options.strictOrder | boolean | If true, signals are not tracked in strict order. If true and signals are received in the wrong order, the promise is rejected. | false | 
| options.rejectOn | Object[] | Array of signals/signal props, which cause promise rejection, if a match is found. | none | 
There is no timeout. The promise can be rejected by setting a custom signal type to options.rejectOn and emit a matching signal.
import { waitForSignals, userRenewalStartedTrigger } from 'hds-react';const createMyCustomModule = (): ConnectedModule => {let beacon: Beacon | undefined;const myCustomRejectSignal = { type: 'reject', namespace: 'myNamespace' };const listener = (signal) => {setTimeout(() => {beacon.emit(myCustomRejectSignal);}, 20000);waitForSignals(beacon, [isUserUpdatedSignal], {rejectOn: [isUserRemovedSignal, isRenewalErrorSignal, myCustomRejectSignal],}).then((signals) => {//}).catch((error) => {//});};return {namespace: helperNamespace,connect: (targetBeacon) => {beacon = targetBeacon;beacon.addListener(userRenewalStartedTrigger, listener);},};};
Object types from oidc-client-ts
The Oidc client module uses the oidc-client-ts. Some of its objects are returned from the module. Their documentation can be found in its repository: