Approve api action helpers
A tiny library that lets you handle Strong Customer Authentication (SCA) required calls easily.
Usage
Installing
npm install @transferwise/approve-api-action-helpers
to install it.
Consuming
This library exports a single function, create
, which creates an SCA request wrapper with a provided config (see available options below). Use it like so:
import { create } from '@transferwise/approve-api-action-helpers';
const request = create({
flow: 'iframe',
mode: 'production',
});
The request function it returns is essentially the same as fetch, except when the backend returns that SCA is required, it will run the user through an SCA flow and retry that request. Also, it will throw an error if you get a 4xx
or 5xx
response.
NB! make sure that your backend proxies 'x-2fa-approval' response header to the frontend and forwards it back to TransferWise when this library passes it back. Also please reflect the response status (403) back to the frontend.
const res = await request('https://my-backend-api.com/sca-protected-call', { options }
Configuration options for create
key | optional | default | alternatives |
---|
flow | yes | 'iframe' | 'tab' |
mode | yes | 'production' | 'sandbox' |
Example
iFrame flow
![sca-iframe-1](https://user-images.githubusercontent.com/39053304/97004007-096d0b00-1545-11eb-8af1-429220cbb065.gif)
New tab flow
![sca-new-tab-1](https://user-images.githubusercontent.com/39053304/97004032-14c03680-1545-11eb-82b1-204484819cdf.gif)