Local First Auth Client Library

2.2.1 · active · verified Wed Apr 22

The `local-first-auth` library provides a client-side implementation of the Local First Auth specification, enabling web applications to integrate authentication without relying on backend servers, passwords, or third-party providers. Currently at version 2.2.1, it focuses on providing a lightweight, DID-based (Decentralized Identifier, specifically `did:key`) authentication flow where user profiles and cryptographic keys are generated and stored locally on the user's device. This approach is ideal for temporary or in-person community applications like meetups, social clubs, or game nights, offering a simple 3-step onboarding process. A key differentiator is its serverless nature and focus on local data storage, which simplifies development for specific use cases. However, users must be aware that clearing browser data will result in the loss of their account keys, making it unsuitable for applications requiring persistent or multi-device account access. The library offers both React components and vanilla JavaScript functions for integration, shipping with TypeScript types.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to integrate the `Onboarding` component into a React application, managing its visibility based on existing local-first authentication state and handling successful profile creation.

import { useState } from 'react';
import { Onboarding } from 'local-first-auth/react';

function App() {
  // Check if localFirstAuth is already initialized in the browser's window object.
  // This helps determine if the user has an existing local-first profile.
  const hasLocalFirstAuth = typeof window !== 'undefined' && window.localFirstAuth;
  const [showOnboarding, setShowOnboarding] = useState(!hasLocalFirstAuth);

  if (showOnboarding) {
    return (
      <Onboarding
        // Callback function invoked upon successful completion of the onboarding process.
        // The 'profile' object contains details like name, avatar, and DID.
        onComplete={(profile) => {
          console.log('Profile created:', profile);
          // Hide the onboarding component after completion.
          setShowOnboarding(false);
        }}
        // Customize the primary accent color of the onboarding UI.
        customStyles={{ primaryColor: '#403B51' }}
      />
    );
  }

  // Render your main application content once onboarding is complete or skipped.
  return (
    <div>
      <h1>Welcome to Your App!</h1>
      <p>Local-first authentication is active.</p>
      {/* Your application's main components would go here */}
      <button onClick={() => setShowOnboarding(true)}>Show Onboarding Again</button> {/* For demonstration */}
    </div>
  );
}

view raw JSON →