Skip to main content

Create Passkey Over Open Session

The simplest and most unrestricted user signup flow, where username and passkey credential is created immediately upon successful sdk called.

To ensure open session, make sure you application is setup with Registration Requires Authentication Token is disabled in your application settings.

When this setting is disabled, users can be created and passkeys can be generated without requiring any authorization tokens. This allows you to simplify the registration in public-facing applications that don’t need strict authentication during the sign-up process.

Here is how it might look like:

Prerequisites

Setup SDK

npm i @loginid/websdk3

Import and initialize an instance:

import { LoginIDWebSDK } from "@loginid/websdk3";

const lid = new LoginIDWebSDK({
baseUrl: process.env.LOGINID_BASE_URL,
});

Creating a Passkey For a New User

Call the createPasskey method by passing in the email or username.

import { LoginIDWebSDK } from "@loginid/websdk3";

// 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 = {
baseUrl: BASE_URL,
appId: APP_ID,
};

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

// Button click handler
async function handleSignupButtonClick() {
const username = "billy@loginid.io";

try {
// Sign up with a passkey
const authResult = await lid.createPasskey(username);

setAuthUser(user);
} catch (error) {
// Handle errors
console.error("Error during signup:", error);
}
}

// Attach the click handler to a button
const signupButton = document.getElementById("signupButton");
signinButton.addEventListener("click", handleSigninButtonClick);