npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@fast-auth-near/react-sdk

v1.0.0-beta.1

Published

React SDK for FastAuth - A provider-agnostic authentication solution for NEAR Protocol.

Readme

@fast-auth/react-sdk

React SDK for FastAuth - A provider-agnostic authentication solution for NEAR Protocol.

Features

  • 🔐 Provider-agnostic: Works with any auth provider implementing the IFastAuthProvider interface
  • ⚛️ React-first: Built with React best practices (hooks, context, memoization)
  • 🎯 Type-safe: Full TypeScript support with comprehensive type definitions
  • 🪝 Multiple hooks: Convenient hooks for common operations
  • 📦 Zero-config: Sensible defaults with full customization options
  • 🔄 State management: Built-in loading, error, and authentication state management

Installation

npm install @fast-auth/react-sdk near-api-js
# or
pnpm add @fast-auth/react-sdk near-api-js
# or
yarn add @fast-auth/react-sdk near-api-js

Compatible Providers

| Provider | Package | Platform | Status | |----------|---------|----------|--------| | React Native (Auth0) | @fast-auth/react-native-provider | React Native (iOS/Android) | ✅ Stable |

Note: You can create custom providers by implementing the IFastAuthProvider interface.

Usage

Basic Setup with React Native Provider

import { FastAuthProvider } from '@fast-auth/react-sdk';
import { reactNativeProviderConfig } from '@fast-auth/react-native-provider';
import { Connection } from 'near-api-js';

// Configure NEAR connection
const connection = new Connection({
  networkId: 'testnet',
  provider: { type: 'JsonRpcProvider', args: { url: 'https://rpc.testnet.near.org' } },
});

// Configure FastAuth network
const network = {
  mpcContractId: 'v1.signer-prod.testnet',
  fastAuthContractId: 'fastauth.testnet',
};

function App() {
  // Configure the ReactNative provider with Auth0 credentials
  const providerConfig = reactNativeProviderConfig({
    domain: 'your-domain.auth0.com',
    clientId: 'your-client-id',
    imageUrl: 'https://your-app.com/icon.png',
    name: 'Your App Name',
    audience: 'your-api-identifier', // optional
  });

  return (
    <FastAuthProvider
      providerConfig={providerConfig}
      connection={connection}
      network={network}
    >
      <YourApp />
    </FastAuthProvider>
  );
}

With Custom Provider

If you want to create a custom provider, implement the IFastAuthProvider interface:

import { FastAuthProvider } from '@fast-auth/react-sdk';
import { Connection } from 'near-api-js';
import { YourCustomProvider } from './your-custom-provider';

const connection = new Connection({
  networkId: 'testnet',
  provider: { type: 'JsonRpcProvider', args: { url: 'https://rpc.testnet.near.org' } },
});

const network = {
  mpcContractId: 'v1.signer-prod.testnet',
  fastAuthContractId: 'fastauth.testnet',
};

function App() {
  const providerConfig = {
    provider: new YourCustomProvider({
      // Your provider configuration
    }),
    // Optional: wrap with a React provider if needed
    reactProvider: (children) => (
      <YourAuthProvider>
        {children}
      </YourAuthProvider>
    ),
  };

  return (
    <FastAuthProvider
      providerConfig={providerConfig}
      connection={connection}
      network={network}
    >
      <YourApp />
    </FastAuthProvider>
  );
}

Hooks

useFastAuth

Main hook to access the FastAuth client and ready state.

import { useFastAuth } from '@fast-auth/react-sdk';

function MyComponent() {
  const { client, isReady } = useFastAuth();

  if (!isReady || !client) {
    return <div>Initializing...</div>;
  }

  // Use client directly for all operations
  const handleLogin = async () => {
    await client.login();
  };

  const handleLogout = async () => {
    await client.logout();
  };

  return (
    <div>
      <button onClick={handleLogin}>Login</button>
      <button onClick={handleLogout}>Logout</button>
    </div>
  );
}

useIsLoggedIn

Convenient hook to check login status with loading and error states.

import { useIsLoggedIn } from '@fast-auth/react-sdk';

function LoginButton() {
  const { isLoggedIn, isLoading, error } = useIsLoggedIn();

  if (isLoading) {
    return <div>Checking status...</div>;
  }

  if (error) {
    return <div>Error: {error.message}</div>;
  }

  return <div>{isLoggedIn ? 'Logged in' : 'Not logged in'}</div>;
}

useSigner

Hook to get the FastAuth signer with automatic state management.

import { useSigner } from '@fast-auth/react-sdk';

function SignerComponent() {
  const { signer, isLoading, error, refetch } = useSigner();

  if (isLoading) {
    return <div>Loading signer...</div>;
  }

  if (error) {
    return <div>Error: {error.message}</div>;
  }

  if (!signer) {
    return <div>Please log in</div>;
  }

  return <div>Signer ready!</div>;
}

usePublicKey

Hook to get the user's public key.

import { usePublicKey } from '@fast-auth/react-sdk';

function PublicKeyDisplay() {
  const { publicKey, isLoading, error } = usePublicKey('ed25519');

  if (isLoading) {
    return <div>Loading public key...</div>;
  }

  if (error) {
    return <div>Error: {error.message}</div>;
  }

  if (!publicKey) {
    return <div>Please log in</div>;
  }

  return <div>Public Key: {publicKey.toString()}</div>;
}

Creating a Custom Provider

To create a custom auth provider, implement the IFastAuthProvider interface:

import { IFastAuthProvider, SignatureRequest } from '@fast-auth/react-sdk';

export class MyCustomProvider implements IFastAuthProvider {
  async isLoggedIn(): Promise<boolean> {
    // Check if user is logged in
    return false;
  }

  async login(...args: any[]): Promise<void> {
    // Implement login logic
  }

  async logout(): Promise<void> {
    // Implement logout logic
  }

  async getPath(): Promise<string> {
    // Return the user's path (e.g., "jwt#https://domain.com/#user-id")
    return "";
  }

  async requestTransactionSignature(...args: any[]): Promise<void> {
    // Request transaction signature from user
  }

  async requestDelegateActionSignature(...args: any[]): Promise<void> {
    // Request delegate action signature from user
  }

  async getSignatureRequest(): Promise<SignatureRequest> {
    // Get the signature request after user approval
    return {
      guardId: "",
      verifyPayload: "",
      signPayload: new Uint8Array(),
      algorithm: "ecdsa",
    };
  }
}

TypeScript

The SDK is fully typed. You can use generic types for better type inference:

import { useFastAuth } from '@fast-auth/react-sdk';
import { MyCustomProvider } from './my-provider';

function MyComponent() {
  const { client } = useFastAuth<MyCustomProvider>();

  // TypeScript will infer the correct types
  const handleLogin = async () => {
    if (client) {
      await client.login(/* correctly typed parameters */);
    }
  };
}

API Reference

FastAuthProvider Props

| Prop | Type | Required | Description | |-------------------|-----------------------------------|----------|--------------------------------------------------| | providerConfig | FastAuthProviderConfig | Yes | Provider configuration | | connection | Connection | Yes | NEAR connection instance | | network | FastAuthClientNetwork | Yes | FastAuth network configuration |

FastAuthProviderConfig

| Property | Type | Required | Description | |------------------|-----------------------------------|----------|--------------------------------------| | provider | IFastAuthProvider | Yes | Auth provider implementation | | reactProvider | (children: ReactNode) => ReactNode | No | Optional React provider wrapper |

FastAuthClientNetwork

| Property | Type | Required | Description | |---------------------|----------|----------|--------------------------------------| | mpcContractId | string | Yes | MPC contract account ID | | fastAuthContractId| string | Yes | FastAuth contract account ID |

IFastAuthProvider Interface

Required methods for custom providers:

| Method | Parameters | Returns | Description | |--------|-----------|---------|-------------| | isLoggedIn | - | Promise<boolean> | Check if user is logged in | | login | ...args: any[] | Promise<void> | Initiate login flow | | logout | - | Promise<void> | Log out user | | getPath | - | Promise<string> | Get user's path identifier | | requestTransactionSignature | ...args: any[] | Promise<void> | Request transaction signature | | requestDelegateActionSignature | ...args: any[] | Promise<void> | Request delegate action signature | | getSignatureRequest | - | Promise<SignatureRequest> | Get signature request after approval |

Hook Return Types

All hooks return objects with loading, error, and data states:

// useIsLoggedIn
{ isLoggedIn: boolean | null; isLoading: boolean; error: Error | null }

// useSigner
{ signer: FastAuthSigner | null; isLoading: boolean; error: Error | null; refetch: () => void }

// usePublicKey
{ publicKey: PublicKey | null; isLoading: boolean; error: Error | null }

// useFastAuth
{ client: FastAuthClient | null; isReady: boolean }

Examples

See the examples/ directory for complete examples using different providers.

Related Packages

License

MIT