> ## Documentation Index
> Fetch the complete documentation index at: https://docs.payunifi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Auth

> Sign up or return with email credentials or a connected MetaMask wallet.

Auth is the gate for wallet, payment, history, and API-management routes. The route stores the page
the user originally requested and returns there after a successful session is established.

![UniFi account screen with an email field and MetaMask option](https://mintcdn.com/test-ccbd1339/a7-7soYiK1kc9L9N/images/web-app/auth.png?fit=max\&auto=format\&n=a7-7soYiK1kc9L9N\&q=85\&s=00fa501138f1be60146e73561ff43973)

Choose an email account or MetaMask to continue.

## Email account flow

For a new email account, the implementation proceeds through:

**1. Verify the email**

Enter a valid email address and submit the six-digit OTP sent by the
configured email service.

**2. Set a password**

The password is hashed client-side with the account identifier before
the login request.

**3. Enable authenticator 2FA**

Scan the generated TOTP QR and confirm a current six-digit code.

**4. Open the requested page**

The web session is stored in the `unifi_user_id` and `unifi_jwt` cookies
and the original route is resumed.

Returning email users complete password and authenticator checks when the backend reports that a
fresh login is required. Recovery routes exist for password reset and 2FA renewal.

## MetaMask flow

MetaMask is offered in desktop web and PWA layouts above 699px. Mobile layouts and native apps
offer email or Unio for sign-in and wallet switching.

The wallet flow requests a server-issued challenge, signs it in MetaMask, and exchanges the
signature for a web JWT. The server checks that the challenge address, origin, chain context,
nonce, and expiry match before issuing the session.

The challenge endpoints do not require an existing bearer credential.

**1. Request a challenge**

POST the expected domain, URI, and chain ID for the wallet address. The
server returns a short-lived message, nonce, and expiry.

**2. Sign the exact message**

Ask the wallet to sign the returned message without altering whitespace
or fields.

**3. Exchange it for a JWT**

POST the message, signature, nonce, and platform. The challenge is
single-use.

**4. Send the JWT**

Use the returned JWT as the bearer credential for protected user routes.

> [!WARNING]
>
> Validate that the challenge domain and URI match the application the user is
> viewing. Reject expired challenges and never reuse a nonce.

> [!NOTE]
>
> Email-based and AWS KMS integrations authenticate through their managed
> UniFi flow. The signed challenge described here is specifically for
> self-custodial wallets.

> [!WARNING]
>
> UniFi never needs a seed phrase or private key. A legitimate login asks the
> wallet to sign the displayed authentication challenge, not to reveal wallet
> secrets.

## Session exit

Email accounts log out; connected-wallet accounts disconnect. Protected pages reuse the shared
logout/disconnect dialog and return to Auth when the session is missing or invalid.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.