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.
npm install @subaio/psd2login-webWrapper 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.
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
``sh`
npm install @subaio/psd2login-web
or
`sh`
yarn add @subaio/psd2login-web
To open a login-window, [[handleLogin]] is used:
`ts
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.
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]]:
`ts
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
}
}