Skip to content
exwave.Docs

Local mock

@exwave-nexus/auth-mock is a stand-in for Exwave Auth that runs on your machine. Your app talks to it the same way it talks to your platform. So you can try every screen before you have a publishable key, and run tests without the network. The mock keeps its accounts in memory, and prints emails in its terminal instead of sending them.

If you made your app with npm create exwave and left out --key, it’s already set up for the mock: .env.local has the mock’s publishable key. Start the mock in a second terminal, while npm run dev runs in the first:

Terminal window
npm run mock

The app’s home page tells you whether it’s using the mock, and whether the mock is running.

In any other app, start the mock with npx:

Terminal window
npx @exwave-nexus/auth-mock

The mock runs at http://localhost:4010 and prints a publishable key. Put that key in .env.local, in place of your own:

.env.local
NEXT_PUBLIC_EXWAVE_PUBLISHABLE_KEY=exw_pk_...
EXWAVE_COOKIE_SECRET=...

When you’re ready to use your platform, put your key from Nexus → Auth back in .env.local.

The mock starts with two accounts. Both use the password Password123!:

Email Username What it’s for
[email protected] player1 A normal account, ready to sign in.
[email protected] unverified An account whose email isn’t verified. Signing in offers a new verification link.

You can also sign up with any other email. The mock prints the verification link in its terminal: open it to verify the account. Password reset links show up there too.

The mock follows the same rules as a new platform:

  • Passwords need at least 8 characters, with an uppercase letter, a lowercase letter, a number and a symbol.
  • Email links may only open http://localhost:3000 and http://localhost:5173.
  • After ten failed sign-ins in 15 minutes, sign-in fails with rate_limited.

Player access tokens from the mock last 15 minutes. The mock doesn’t have the hosted sign-in pages that engines and launchers use, so test that flow against your platform.

To see how your app handles errors, use the mock’s own controls, under http://localhost:4010/__mock/:

Terminal window
# List the accounts, with their status and open sessions
curl http://localhost:4010/__mock/players
# Lock an account (use /unlock to undo it)
curl -X POST http://localhost:4010/__mock/players/player1/lock
# List every email the mock has "sent", with its link
curl http://localhost:4010/__mock/emails

Locking an account ends its sessions. Until you unlock it, signing in fails with player_locked. See Errors for what each error code means.

Pass options after the command, for example npx @exwave-nexus/auth-mock --port 4011. With npm run mock, add -- first: npm run mock -- --port 4011.

Option Default What it does
--port 4010 The port the mock listens on. The publishable key depends on the port, so use the key the mock prints. You can also set MOCK_AUTH_PORT.
--pat-ttl 900 How long player access tokens last, in seconds. Set a short time, such as 120, to see your game ask for new tokens. You can also set MOCK_PAT_TTL.

Install the mock as a dev dependency:

Terminal window
npm install --save-dev @exwave-nexus/auth-mock

In tests, you don’t need to start a server. createMockAuth() creates a mock inside your test process, and its fetcher() lets the client call it directly, without the network:

import { createExwaveAuth, memoryStorage } from "@exwave-nexus/auth";
import { createMockAuth } from "@exwave-nexus/auth-mock";
const mock = await createMockAuth({ log: () => {} });
const auth = createExwaveAuth({
publishableKey: mock.publishableKey,
storage: memoryStorage(),
fetch: mock.fetcher(),
});
await auth.signIn({ login: "player1", password: "Password123!" });

createMockAuth() takes these options:

Option What it does
passwordPolicy Sets other password rules, such as { min_length: 12 }.
signUpEnabled false acts like a platform with sign-up turned off.
allowedRedirectOrigins Sets the Redirect URLs the mock accepts.
patTtlSeconds Sets how long player access tokens last, in seconds.
now Gives the mock your own clock, so you can move time forward.
seed false starts the mock with no accounts.
log Where the mock’s log lines go. () => {} keeps your tests quiet.

In your tests, mock.emails holds the emails the mock has sent, each with its link and code. mock.lock("player1") locks an account.

To serve the mock over HTTP instead, for a browser or another process, use startMockServer({ port: 0 }). With port 0, it picks a free port. Call its close() to stop it.