Getting Started

Direct Sign-In

Add the direct Better Auth plugin and client helpers for Nimiq Pay mini-app auth.

Direct Sign-In

Use @onmax/better-auth-nimiq-pay when the current browser already runs inside the Nimiq Pay mini-app and can call window.nimiq directly.

Register the server plugin

server/auth.config.ts
import { nimiqPay } from '@onmax/better-auth-nimiq-pay'
import { bearer } from 'better-auth/plugins'

export default {
  plugins: [
    bearer({ requireSignature: true }),
    nimiqPay({
      appName: 'My Mini App',
      endpointPrefix: '/nimiq',
    }),
  ],
}

The plugin exposes two endpoints:

  • POST /nimiq/nonce
  • POST /nimiq/verify

Register the client helper

app/auth.config.ts
import { nimiqPayClient } from '@onmax/better-auth-nimiq-pay/client'

export default {
  plugins: [nimiqPayClient()],
}

Trigger the flow

sign-in.ts
import { signInWithNimiqMiniApp } from '@onmax/better-auth-nimiq-pay/client'

await signInWithNimiqMiniApp(authClient.$fetch.bind(authClient), {
  appName: 'My Mini App',
  endpointPrefix: '/nimiq',
})

What the plugin stores

The plugin creates a Better Auth model named nimiqAccount by default. Each record links one normalized public key to one Better Auth user.

If the client also sends an address, the plugin validates it with @nimiq/utils and stores the normalized uppercase format without spaces.

Keep appName and endpointPrefix identical on the client and server. The message format includes the app name, so mismatches break verification.
Copyright © 2026