react-native-pluggy-connect
v1.6.0
Published
Pluggy Connect SDK for React Native.
Keywords
Readme
React Native Pluggy Connect SDK
React Native bindings for our Pluggy Connect widget.
Setup
Using npm
npm install react-native-webview react-native-pluggy-connectUsing yarn
yarn add -S react-native-webview react-native-pluggy-connectUsage
Please check out our Connect React Native quickstart repo for a fully-working example you can use to get started right away.
Typescript Support
This project was built using Typescript so all typings are natively built-in.
However, for up-to-date Pluggy API typings to work, you'll need to install pluggy-js in your project as well, either
as a dev or prod dependency.
npm install pluggy-jsOauth Support
To fully support Oauth you need to follow the following guide: https://docs.pluggy.ai/docs/oauth-support-guide
Where the Oauth URL is opened
By default (forceOauthInBrowser: true), the connector Oauth URL is opened in the system browser
(or in the institution app, if it can handle the link). In this mode the SDK can't track the Oauth
result: the connection is resolved by Connect polling the Item status once the user comes back to the app.
Setting forceOauthInBrowser: false keeps the whole flow inside the app: the Oauth URL is opened in a
dedicated WebView, and its callback result is forwarded back to the Connect WebView as soon as the
institution redirects back. This is useful for apps where leaving the app to the system browser breaks
the flow (for example, on iOS, when the connection stays waiting for user input until it times out with
USER_INPUT_TIMEOUT).
Note that some connectors (e.g. Open Finance Sandbox, some regulated connectors with one-time-use links,
or connectors that continue the login in the institution app through an intent:// link) are only known
to work reliably with the default browser mode, so change it only if you need to.
Configurations
The available configuration props are the following.
See our official Pluggy Connect widget documentation for more detailed information.
| Property | Description | Required? | Type | Default |
| -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
| connectToken | Your Pluggy Connect token, which will be used to access the API. | ✅ | string | N/A |
| includeSandbox | Whether to display Sandbox connectors in the Connector selection step (not intended for production use) | | boolean | false |
| allowConnectInBackground | If true, Connect can be minimized by the user to continue the connection with the component hidden | | boolean | false |
| updateItem | Item id to update. If specified, the modal will display directly the credentials form of the item to be updated. | | string | N/A |
| connectorTypes | List of Connector Types. If defined, only Connectors of the specified connector types will be listed. | | ConnectorType[] | N/A |
| connectorIds | List of Connector IDs. If defined, only Connectors of the specified connector IDs will be listed. | | number[] | N/A |
| countries | List of country codes (ISO-3166-1 alpha 2 format). If defined, only Connectors of the specified countries will be listed. | | CountryCode[] | N/A |
| selectedConnectorId | If specified and the Connector is present, after accepting terms, the widget will navigate to this Connector login form directly, skipping connectors selection step. | | number | N/A |
| language | Language (2-letter ISO code string), used to display the widget. If not specified, or if the selected language is not supported, the default 'pt' will be used. | | string | 'pt' |
| theme | Theme to use for displaying the UI. Can be 'light' or 'dark'. Defaults to 'light' | | 'light' | 'dark' | 'light' |
| openFinanceParameters | Object with CPF and CNPJ for Open Finance connectors only, the form will be pre-filled with these values. Contains optional cpf and cnpj string fields. | | { cpf?: string; cnpj?: string } | N/A |
| connectorSortAlphabetically | If set to true, connectors will be sorted alphabetically (A-Z) instead of by usage. | | boolean | false |
| forceOauthInBrowser | If true (default), OAuth URLs are opened in the system browser. If false, they are opened in a WebView inside the app. See Oauth Support. | | boolean | true |
| onSuccess | Function to execute when an Item has been created/updated successfully. | | (data: { item: Item }) => void | Promise<void> | No op |
| onError | Function to execute on a general error loading the widget, or when an Item creation/update status has not been successful. | | (error: { message: string; data?: { item: Item } }) => void | Promise<void> | No op |
| onOpen | Function to execute when the widget modal has been opened. | | () => void | Promise<void> | No op |
| onClose | Function to execute when the widget modal has been closed. | | () => void | Promise<void> | No op |
| onEvent | Function to execute to handle custom user interaction events. See the docs for more info. | | Since v2.0.0: (payload: ConnectEventPayload) => void | Promise<void> Until 1.x: (event: string, metadata: { timestamp: number }) => void | No op |
onEvent
This callback allows handling more specific events.
The property event inside the payload param of the onEvent callback, is the name of the current event triggered.
The available events that can be handled through this method are:
| Event name | Description |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 'SUBMITTED_CONSENT' | User has confirmed terms & privacy consent on the first Welcome screen. |
| 'SELECTED_INSTITUTION' | User has selected an institution to connect to, or has deselected it (ie. navigated back to previous step). |
| 'SUBMITTED_LOGIN' | User has submitted credentials to create the connection Item. |
| 'SUBMITTED_MFA' | User has submitted an extra parameter that has been requested by the institution to connect. |
| 'LOGIN_SUCCESS' | User has submitted credentials to create the connection Item successfully. |
| 'LOGIN_MFA_SUCCESS' | User has submitted an extra parameter that has been requested by the institution to connect successfully. |
| 'LOGIN_STEP_COMPLETED' | Successful completion of the login. User effectively logged in to the institution. |
| 'ITEM_RESPONSE' | Called every time the Item object is retrieved from Pluggy API, either when just created, updated, or each time it's retrieved to poll it's connection/execution status. |
payload object has a property timestamp and some events extra data:
'SELECTED_INSTITUTION' has the connector property which is the connector selected by the user.
'LOGIN_SUCCESS' | 'LOGIN_MFA_SUCCESS' | 'LOGIN_STEP_COMPLETED' | 'ITEM_RESPONSE' events have the item property which is the item data related to the current connection.
Full event parameter type definition is:
type ConnectEventPayload = {
timestamp: number;
} & (
| {
event: 'SUBMITTED_CONSENT' | 'SUBMITTED_LOGIN' | 'SUBMITTED_MFA';
}
| {
event: 'SELECTED_INSTITUTION';
connector: Connector | null;
}
| {
event: 'LOGIN_SUCCESS' | 'LOGIN_MFA_SUCCESS' | 'LOGIN_STEP_COMPLETED' | 'ITEM_RESPONSE';
item: Item;
}
);Development
The example/ folder contains an Expo app that runs the library straight from src/, to test changes locally.
# install the library and the example dependencies
yarn bootstrap
# start the dev server, and open it with Expo Go on your device
yarn example start
# or build & run a native app, to test it on a simulator or a development build
yarn example ios
yarn example androidThe example links the library with "react-native-pluggy-connect": "link:..", and metro watches the repository
root, so any change in src/ is picked up by fast refresh without rebuilding the library.
The forceOauthInBrowser toggle on the example home screen lets you test both Oauth flows.
