Skip to content

Getting Started

Components List

NameTypeDescription
np-logininputAuthenticate a user with a magic link or passkey
np-passkey-registerbuttonRegister a passkey
np-logoutbuttonRevoke the current session
np-ifslotRender specific slots based on user’s session states

How to Install

You can load our web components via CDN or install them locally using a package manager like NPM.

Each component (np-login, np-passkey-register, np-logout, np-if) can be loaded individually from a CDN.

Example using the email link authentication button component:

<script
type="module"
src="https://cdn.jsdelivr.net/npm/@nopwdio/sdk-js@latest/cdn/components/{component-name}.js"
></script>

Since modules are loaded asynchronously, the component may not be available during the initial render, causing a Flash of Undefined Custom Elements (FOUCE) when the page loads.

How to Prevent FOUCE

One option is to use the :defined CSS pseudo-class to hide custom elements that haven’t been registered yet.

np-login:not(:defined) {
visibility: hidden;
}

Another option is to use the customElements.whenDefined() function, which returns a promise that resolves when the specified element is registered. You can then add a specific class to adjust the CSS accordingly.

await customElements.whenDefined("np-login");
document.body.classList.add("ready");

CDN vs NPM

TL;DR: Use @nopwdio/sdk-js/cdn for CDN and @nopwdio/sdk-js/dist for NPM.

CDN links start with /cdn and npm imports use /dist. The /cdn files are pre-bundled and minified, with code splitting for optimal bandwidth usage. The /dist files are not pre-bundled, allowing your bundler to efficiently deduplicate dependencies, resulting in smaller bundles and optimal code sharing.