Skip to content

Email Link Authentication

Also known as a magic link, email authentication is a passwordless method where users log in by clicking a unique link sent to their email address.

Add the np-login Input Component

From your login page, add the <np-login> component.

Once the user enters their email address and submits it, an authentication email is sent to that address. By clicking the authorization link in the email, the user will be redirected to the original page with an additional code parameter. The component will use this code to create the user session and emit a np:login event.

const el = document.querySelector("np-login");
el.addEventListener("np:login", async (e) => {
// A session has been created 🎉
const { expires_at, token } = await e.target.getSession();
});

You Are Done!

Once the session is established, transmit the session token to your server and verify it.