SIWE user not created

I am able to log in via SIWE, but a user account is not created in the BA database. Perhaps this is because I have BA server on a dedicated API repo, BA client on a React app repo? Or am I missing config? I have ran DB migrations and web3 things (e.g. wallet address table) are present

Server (localhost:4000):
import { generateRandomString } from "better-auth/crypto";
import { betterAuth } from "better-auth";
import { siwe } from "better-auth/plugins";
import { verifyMessage, createPublicClient, http } from "viem";
import { mainnet } from "viem/chains";

export const auth = betterAuth({
  baseURL: "https://localhost:4000",
  // ...other config (e.g. DB)
  secret: "redacted",
  plugins: [
    siwe({
      domain: "localhost:3000",
      emailDomainName: "localhost",
      // tried both
      anonymous: true,
      // anonymous: false,
      getNonce: async () => generateRandomString(32),
      verifyMessage: async ({ message, signature, address }) => {
        try {
          const isValid = await verifyMessage({
            address: address as `0x${string}`,
            message,
            signature: signature as `0x${string}`,
          });
          
          return isValid;
        } catch (error) {
          console.error("SIWE verification failed:", error);
          
          return false;
        }
      },
      ensLookup: async ({ walletAddress }) => {
        try {
          const client = createPublicClient({
            chain: mainnet,
            transport: http(),
          });
          
          const ensName = await client.getEnsName({
            address: walletAddress as `0x${string}`,
          });
          
          const ensAvatar = ensName
            ? await client.getEnsAvatar({
                name: ensName,
              })
            : null;
          
          return {
            name: ensName || walletAddress,
            avatar: ensAvatar || "",
          };
        } catch {
          return {
            name: walletAddress,
            avatar: "",
          };
        }
      },
    }),
  ],
});


Client (localhost:3000):
import { createAuthClient } from "better-auth/react";
import { siweClient } from "better-auth/client/plugins";

export const authClient = createAuthClient({
  baseURL: "https://localhost:4000",
  plugins: [siweClient()],
});
Was this page helpful?