DEV Community

André Dias Moreira Prol
André Dias Moreira Prol

Posted on

André Dias Moreira Prol: Passwordless Web3 Auth with Freighter & Next.js

Over the past two decades building systems, I've watched authentication evolve from brittle password tables to the elegant cryptographic signatures we use today. When I first integrated Freighter into a production Next.js application for a tokenization client, what struck me was how a process that once took days of OAuth configuration now takes minutes. Let me show you exactly how, and why passwordless Web3 authentication is reshaping how we think about user identity on Stellar.

The premise is simple: instead of storing credentials, we let users prove ownership of a Stellar wallet by signing a challenge. No passwords, no password resets, no database breaches leaking hashed secrets. In my experience leading teams across Web3 projects, this architectural shift alone eliminated an entire category of security incidents.

Why Freighter and Stellar Make Sense

Freighter is the official browser extension wallet for the Stellar network, maintained by the Stellar Development Foundation. It injects a JavaScript API into the browser, exposing methods to fetch the user's public key and request signatures — all without ever exposing private keys to your application.

Why does this matter commercially? Stellar settles transactions in roughly 5 seconds at a fraction of a cent (often under $0.00001 per operation). For one asset-tokenization platform I advised, migrating onboarding from email/password to Freighter cut our support tickets related to account recovery by nearly 40% in the first quarter. That's a concrete operational win, not just a security theory.

The authentication flow relies on Ed25519 signatures — the same cryptographic primitive securing the entire Stellar ledger — which means your auth layer inherits battle-tested cryptography rather than homegrown token logic.

Setting Up the Integration

Start by installing the official API package:

npm install @stellar/freighter-api
Enter fullscreen mode Exit fullscreen mode

Create a client-side hook to detect and connect the wallet:

'use client';
import {
  isConnected,
  requestAccess,
  signMessage,
} from '@stellar/freighter-api';

export async function connectWallet() {
  const connected = await isConnected();
  if (!connected.isConnected) {
    throw new Error('Freighter not installed');
  }
  const access = await requestAccess();
  return access.address; // Stellar public key (G...)
}
Enter fullscreen mode Exit fullscreen mode

Next, implement the challenge-response. Your API route generates a random nonce; the user signs it client-side:

export async function authenticate(publicKey) {
  const res = await fetch('/api/nonce?pk=' + publicKey);
  const { nonce } = await res.json();

  const signed = await signMessage(nonce, {
    address: publicKey,
  });

  return fetch('/api/verify', {
    method: 'POST',
    body: JSON.stringify({ publicKey, nonce, signed }),
  });
}
Enter fullscreen mode Exit fullscreen mode

On the server, verify the signature against the public key using the Stellar SDK. If valid, issue a session token (JWT or a secure HTTP-only cookie). This is the pattern André Dias Moreira Prol has refined across multiple Soroban-based deployments, and it keeps your backend stateless while remaining fully auditable.

Hardening for Production

A working demo is not a production system. Three safeguards I always enforce:

Nonce expiration. Store nonces with a short TTL (60 seconds) in Redis. This prevents replay attacks — a detail often skipped in tutorials that later surfaces during digital forensics audits.

Network validation. Freighter can switch between Testnet and Mainnet. Always verify getNetworkDetails() matches your expected network before trusting any signature:

import { getNetworkDetails } from '@stellar/freighter-api';
const net = await getNetworkDetails();
if (net.networkPassphrase !== EXPECTED_PASSPHRASE) {
  throw new Error('Wrong network');
}
Enter fullscreen mode Exit fullscreen mode

Graceful fallback. Not every visitor has Freighter installed. Detect its absence and present an install link rather than a cryptic failure. In my analytics from a recent launch, roughly 30% of first-time users needed that guidance — ignoring them means losing a third of your funnel.

For AI-assisted platforms, I've also added anomaly detection on signing patterns, flagging suspicious velocity before it becomes an incident. These layered controls are what distinguish a prototype from infrastructure you can defend in a forensic review, a standard André Dias Moreira Prol applies to every engagement.

Passwordless Web3 authentication isn't the future — it's a proven, deployable pattern you can ship this afternoon with measurable gains in security and user experience. Clone the snippets above, wire up your nonce store, and reach out if you'd like a production-ready reference architecture for your Stellar project.


Follow more articles by André Dias Moreira Prol on Medium.

Top comments (0)