Skip to content

<np-login>

An input component to authenticate a user using an authentication link or passkeys (if registered).

Usage:

<!-- Works out of the box -->
<np-login></np-login>
<!-- Customize the placeholder -->
<np-login placeholder="Enter your email"></np-login>
<!-- Set the session lifetime -->
<np-login lifetime="86400"></np-login>
<!-- Set the session idle timeout -->
<np-login idletimeout="3600" lifetime="86400"></np-login>

Properties

NameTypeRequiredDefaultDescription
idtextno”input”The input component id.
valueemailnoundefinedThe user’s email.
placeholdertextno”Your email”The input field placeholder.
passkeysbooleannoundefinedTrue if passkeys are supported and ready to authenticate.
stateStatenoundefinedThe component’s internal state.
lifetimenumberno”86400” (24h)The session maximum duration in seconds.
idletimeoutnumbernolifetimeThe session inactivity timeout in seconds.
enum State {
EMAIL_SENDING = "email:link:sending", // Sending an email link
EMAIL_SENT = "email:link:sent", // The email link has been sent
EMAIL_VERIFYING = "email:link:verifying", // Verifying the callback code from the email link
AUTHENTICATED = "authenticated", // The user is authenticated (using email or passkey)
PASSKEYS_VERIFYING = "passkeys:verifying", // The user is authenticating with passkey
ERROR = "error", // An error occurred
}

Methods

NameDescription
loginWithEmail()Starts the email link login flow programmatically. Set the email property before calling it.
getSession()Returns the current session (Promise<Session>). Null if not authenticated.

Custom Events

NameDescriptionType
np:loginThe user has been authenticated.Session
np:errorSomething went wrong.NoPwdError

The np:login custom event detail is defined as follows:

// AuthEvent type definition
interface Session {
created_at: number; // When the session was created
expires_at: number; // The session expiration date
idle_lifetime: number; // The session idle lifetime
token: string; // The last generated token
refreshed_at: number; // When a new token was generated
token_payload: TokenPayload; // Its payload
suggest_passkeys: boolean; // True if the user doesn't use a passkey and the browser supports it
}

The np:error custom event detail inherits from the NoPwdError.

Parts

NameDescription
inputThe component’s input wrapper.
buttonThe component’s button wrapper.