🚀
Tonomy Developer Docs
  • Introduction
    • Features
  • Build Web4 Apps
    • Install
    • Register your Web4 App
    • Login
    • User Data and Logout
    • Sign Verifiable Credentials
    • Server Authentication
    • Smart Contracts
      • Develop
      • Deploy
      • 1-Click Transactions
      • Wallet Signing
    • Send P2P Messages
    • Troubleshooting
  • Multi-Chain Transactions + Crypto
    • Wallet Connect
    • Antelope Sigining Request (ESR)
  • Run Tonomy Infrastructure
    • Overview
      • Configuration
      • What software to run?
    • Node Setup
      • Setup
      • Run an API Node
      • Run a Block Producer Node
      • Becoming a Block Producer on Tonomy
    • API Endpoints
    • Hardware Requirement
    • Troubleshooting
  • Connect as an Exchange
  • Run Tonomy Gov OS
    • Technical requirements
    • Deploy Tonomy ID
    • Deploy a web wallet with the SDK
    • Reference
      • Application Interface (API)
      • Software Development Kit (SDK)
    • Troubleshooting
Powered by GitBook
On this page
  • Before You Start
  • 1. Configure network
  • 2. Open Login Flow
  • Request data sharing
  • 3. Callback page
  • 4. Persist User Session
  1. Build Web4 Apps

Login

PreviousRegister your Web4 AppNextUser Data and Logout

Last updated 22 days ago

Tonomy ID allows users to log in securely without passwords, eliminating credential phishing risks and reducing login friction. This is ideal for Web2 apps needing high-security authentication or privacy by default and Web3 apps requiring private key-based transaction authorization.

Before You Start

Ensure your app is registered with the Tonomynetwork (See )

For local testing, run your app on and connect to the testnet

1. Configure network

Set your network at the start of your app (e.g., in App.tsx for React):

import { setSettings } from '@tonomy/tonomy-id-sdk';

//Testnet Configuration
setSettings({
    ssoWebsiteOrigin: "https://accounts.testnet.tonomy.io",
    blockchainUrl: "https://blockchain-api-testnet.tonomy.io"
});

//Mainnet Configuration
setSettings({
    ssoWebsiteOrigin: "https://accounts.tonomy.io",
    blockchainUrl: "https://blockchain-api.tonomy.io"
});

2. Open Login Flow

This will open the Tonomy ID app (via QR or deep link)

/login
import { ExternalUser } from '@tonomy/tonomy-id-sdk';

async function onButtonPress() {
    await ExternalUser.loginWithTonomy({ callbackPath: '/callback' });
}

Request data sharing

Request user information by adding a dataRequest object.

/login
const dataRequest = { username: true };
await ExternalUser.loginWithTonomy({ callbackPath: '/callback', dataRequest, });

3. Callback page

On your /callback page:

/callback
const user = await ExternalUser.verifyLoginRequest();

4. Persist User Session

Check user status when your app starts (e.g., in App.tsx):

import { ExternalUser, SdkError, SdkErrors } from '@tonomy/tonomy-id-sdk';

async function checkSession() {
  try {
    const user = await ExternalUser.getUser();
    console.log('User session:', user);
  } catch (e) {
    if (e instanceof SdkError) {
      switch (e.code) {
        case SdkErrors.AccountNotFound:
        case SdkErrors.UserNotLoggedIn:
          console.log('User not logged in');
          break;
        default:
          console.error('Unexpected error:', e);
      }
    } else {
      console.error('Error fetching user:', e);
    }
  }
}
Register Your Web4 App
http://localhost:3000