better-auth-siws is a specialized plugin designed to integrate Sign-In With Solana (SIWS) functionality into applications utilizing the Better Auth framework. Currently at version 0.1.3, this package provides both server-side and client-side plugins (`siwsPlugin` and `siwsClientPlugin` respectively) along with a utility (`buildSiwsMessage`) to construct the canonical SIWS message. It streamlines the implementation of SIWS by offering `start` and `verify` endpoints, abstracting away much of the cryptographic and session management complexity when paired with Better Auth. The package is actively maintained and extends Better Auth's capabilities to support Solana-based authentication flows, differentiating itself by providing a tightly integrated solution specifically for the Better Auth ecosystem.
npm install better-auth-siwsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates a complete client-side Sign-In With Solana (SIWS) flow using `better-auth-siws`. It covers initializing the Better Auth client, requesting a nonce from the server, building the canonical SIWS message, having a mock Solana wallet sign the message, and finally verifying the signature with the server to establish a user session. This illustrates the typical steps a user would take in a web application.
Ensure `siwsPlugin({ domain: 'app.example.com' })` on the server exactly matches your application's domain. Also, `betterAuth({ security: { trustedOrigins: [...] } })` should include the exact client origin.Inform users about the time limit or consider increasing `nonceTtlSeconds` on the server if longer delays are expected. For example: `siwsPlugin({ nonceTtlSeconds: 600 })`.Ensure you are using a compatible Solana wallet adapter (e.g., `@solana/wallet-adapter`) and that the wallet is connected and exposes the `signMessage` function as expected.
Verify your `better-auth` server configuration, ensuring `baseURL` is correct and all client origins are listed in `security.trustedOrigins`.
Check the `domain` option passed to `siwsPlugin({ domain: '...' })` on your server to ensure it precisely matches the `domain` of your application where the SIWS flow is initiated.Expedite the client-side signing process, or increase the `nonceTtlSeconds` option in your server's `siwsPlugin` configuration (e.g., `siwsPlugin({ nonceTtlSeconds: 600 })`).Ensure a compatible Solana wallet (e.g., via `@solana/wallet-adapter`) is connected and the wallet instance provides the `signMessage` function with the expected signature (`(data: Uint8Array) => Promise<Uint8Array>`).
Add the full origin URL of your frontend application (e.g., `https://app.example.com`) to the `trustedOrigins` array in your `betterAuth({ security: { trustedOrigins: [...] } })` server configuration.