Plugins

Username

Official plugin — username + password sign-up and sign-in under /auth, plugged onto gate.auth.

username() lets people register and sign in with a username instead of email. It adds two public Flows under /auth and contributes the oke_usernames table.

The one rule

Enable gate.auth first, then .plug(username()). The plugin .needs("auth") and joins the HTTP router via Bindings — not registry metadata alone.

Quick start

Plug it

src/app.ts
import { oke } from "okengine";
import { username } from "okengine/plugins";

export const app = oke({
  name: "shop",
  env: "dev",
  gate: { auth: {} },
}).plug(username());

Sign up

const { data, error } = await api.auth.signUpUsername({
  username: "ali",
  password: "CorrectHorse1",
});

POST /auth/sign-up/username — usernames are normalized to lowercase; allowed pattern [a-z0-9._-]{3,64}.

Sign in

const { data } = await api.auth.signInUsername({
  username: "ali",
  password: "CorrectHorse1",
});
// data: accessToken, refreshToken, accessExpiresAt, userId

Unknown username and bad password both return AuthFailed with reason: "invalid_credentials" (enumeration-safe).

Options

OptionTypeDefaultMeaning
secretstringactive*HMAC secret (*from gate.auth when plugged after oke())
sessionsSessionStoreactive*Session store shared with Gate auth
now() => numberDate.nowInjectable clock
usernamesUsernameStorenew mapShared in-memory credential store

Surfaces

FlowPathGate
auth.signUpUsernamePOST /auth/sign-up/usernamegate.public + sign-up rate
auth.signInUsernamePOST /auth/sign-in/usernamegate.public + sign-in rate

Troubleshooting

Learn more

Next

On this page