Options
All
  • Public
  • Public/Protected
  • All
Menu

@subaio/psd2login-web

Subaio PSD2 login for Web

Wrapper library to show PSD2 login page in a small popup window instead of redirecting the main page. Since a primary-context (non-iframe) is used to show the login pages, they can be allowed to use cookies without being flagged as third-party.

Installation

Before installing, a method of accessing the private Subaio npm repository where the package can be found must be established. This is likely done by proxying an artifact repository, but details for this is out of scope for this document. After adding @subaio as a scoped repository, the package can be installed with

npm install @subaio/psd2login-web

or

yarn add @subaio/psd2login-web

Usage

To open a login-window, handleLogin is used:

import { handleLogin } from '@subaio/psd2login-web'

...

someButton.addEventListener('click', async () => {
await handleLogin({ url: providedRedirectUrl })
})

After the promise resolves, Subaio will begin processing data in the background.

Note that the redirect URL should be made available before the button is clicked, so the handle-login function is invoked immediately in the click-handler. This is because browsers may consider a window an intrusive popup if it is not spawned as part of a user action.

Error handling

If at least one bank is added through the login window, the promise will resolve. If the user aborts the login or something unexpected happens, the promise will reject with a Psd2Error:

import { handleLogin, Psd2Error, Psd2ErrorType } from '@subaio/psd2login-web'

try {
await handleLogin({ url: providedRedirectUrl })
} catch (error) {
if (!(error instanceof Psd2Error)) {
// Some unknown script error
}
switch (error.type) {
case Psd2ErrorType.Aborted:
// User closed the window before completing the login, let them
// reopen it
break
case Psd2ErrorType.FailedToOpen:
// The window failed to open, possibly because of browser settings
// or calling `handleLogin` outside of direct user interaction
break
default:
// Something unexpected happened
break
}
}

Generated using TypeDoc