Skip to main content

Overview

Solana wallets can be used for authentication through message signing. This enables passwordless, blockchain-based authentication for your dApps.

Sign-In With Solana (SIWS)

Sign-In With Solana is a standard for wallet-based authentication. The signIn method works identically whether you’re using web3.js or Kit - choose whichever architecture fits your project.
  • React
  • Vanilla TS
import { useWallet } from '@hermis/solana-headless-react';

function SignInButton() {
  const { signIn } = useWallet();

  const handleSignIn = async () => {
    try {
      const { account, signedMessage, signature } = await signIn({
        domain: window.location.host,
        statement: 'Sign in to MyDApp',
        uri: window.location.origin,
      });

      // Verify signature on your backend using:
      // - account.address (user's public key)
      // - signedMessage (the message that was signed)
      // - signature (the cryptographic signature)
      // Then create a session token or JWT

      console.log('Signed in:', account.address);
    } catch (error) {
      console.error('Sign in failed:', error);
    }
  };

  return <button onClick={handleSignIn}>Sign In</button>;
}

What’s Next?