by @cameronapak
Use when setting up user registration flows in a Bknd application. Covers registration configuration, enabling/disabling registration, default roles, password validation, registration forms, and custom fields.
Configure and implement user self-registration in Bknd applications.
bknd-setup-auth)bknd package installedUI steps: Admin Panel > Auth > Test password/register endpoint
import { serve } from "bknd/adapter/bun";
serve({
connection: { url: "file:data.db" },
config: {
auth: {
enabled: true,
allow_register: true, // Enable self-registration (default: true)
default_role_register: "user", // Role assigned on registration
strategies: {
password: {
type: "password",
config: {
hashing: "bcrypt", // "plain" | "sha256" | "bcrypt"
minLength: 8, // Minimum password length
},
},
},
roles: {
user: { implicit_allow: false },
},
},
},
});
Config options:
| Option | Type | Default | Description |
|---|---|---|---|
allow_register | boolean | true | Enable self-registration |
default_role_register | string | - | Role for new users |
minLength | number | 8 | Minimum password length |
import { Api } from "bknd";
const api = new Api({
host: "http://localhost:7654",
storage: localStorage, // Persist token
});
async function register(email: string, password: string) {
const { ok, data, status } = await api.auth.register("password", {
email,
password,
});
if (ok) {
// Token stored automatically - user is logged in
return data.user;
}
if (status === 409) throw new Error("Email already r...