Skip to main content
Version: 2.0.0-beta

How to Authenticate a User

Users must first be registered before authentication. Registered users must be authenticated via the same route. A user is registered via passkey must also be authenticated via passkey, not email verification.

Below are a few examples using our SDKs. If you'd like a more detailed look at the API, please take a look at the OpenAPI Specs.


Prerequisites

Create Web Tenant

Use an existing tenant or create a new one to obtain the project base URL and application ID.

Authenticate a User via Passkey

Below is an example using our Web SDK Javascript to authenticate a user via Passkey.

Web SDK Javascript
import { LoginIdConfiguration, LoginIdPasskey } from "@loginid/web-sdk";

// Obtain credentials from LoginID Tenant
const BASE_URL = process.env.BASE_URL;
const APP_ID = process.env.APP_ID;

// Initialize the SDK with your configuration
const config = new LoginIdConfiguration(BASE_URL, APP_ID);

// Use the SDK components for signup and signin
const lid = new LoginIdPasskey(config);

// Button click handler for signing in
async function handleSigninButtonClick() {
const username = "exampleUser";

try {
// Sign in with a passkey
const signinResult = await lid.signinWithPasskey(username);
// Handle the sign-in result
console.log("Signin Result:", signinResult);
} catch (error) {
// Handle errors
console.error("Error during signin:", error);
}
}

// Attach the click handler to a button
const signinButton = document.getElementById("signinButton"); // Assuming you have a button with id 'signinButton'
signinButton.addEventListener("click", handleSigninButtonClick);

Authenticate a User via Email

Below is an example using our Web SDK Javascript to authenticate a user via email verification.

import { LoginIdConfiguration, LoginIdEmail } from "@loginid/web-sdk";

// Obtain credentials from LoginID Tenant
const BASE_URL = process.env.BASE_URL;
const APP_ID = process.env.APP_ID;

// Initialize the SDK with your configuration
const config = new LoginIdConfiguration(BASE_URL, APP_ID);

// Use the SDK components for signup and signin
const lid = new LoginIdEmail(config);

// Button click handler
async function handleSigninButtonClick() {
const username = "johnny@email.com";

try {
// Sign up with email
const signinResult = await lid.signinWithEmail(username);
// Handle the signup result
console.log("Signup Result:", signinResult);
} catch (error) {
// Handle errors
console.error("Error during signup:", error);
}
}

// Attach the click handler to a button
const signinButton = document.getElementById("signinButton"); // Assuming you have a button with id 'signupButton'
signupButton.addEventListener("click", handleSigninButtonClick);

More Examples

  • Check out our quickstart guide to learn how to:
    • how to handle passkey authentication
    • use email verification sign-in as a fallback if passkey sign in fails or is unavailable with the WebSDK.