@subaio/psd2login-web
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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
	}
}

Readme

Keywords

none

Package Sidebar

Install

npm i @subaio/psd2login-web

Weekly Downloads

58

Version

1.0.0

License

UNLICENSED

Unpacked Size

257 kB

Total Files

37

Last publish

Collaborators

  • brian_subaio
  • kgram