bknd-registration
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.
What this skill does
# User Registration Setup
Configure and implement user self-registration in Bknd applications.
## Prerequisites
- Bknd project with auth enabled (`bknd-setup-auth`)
- Password strategy configured
- For SDK: `bknd` package installed
## When to Use UI Mode
- Testing registration endpoint via admin panel
- Viewing registered users
**UI steps:** Admin Panel > Auth > Test password/register endpoint
## When to Use Code Mode
- Building registration forms in frontend
- Configuring registration settings
- Adding validation and error handling
## Registration Configuration
### Enable/Disable Registration
```typescript
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 |
## SDK Registration
```typescript
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 registered");
if (status === 400) throw new Error("Invalid email or password");
throw new Error("Registration failed");
}
```
**Response:**
```typescript
{
ok: boolean;
data?: {
user: { id: number; email: string; role?: string };
token: string;
};
status: number;
}
```
## REST API Registration
```bash
curl -X POST http://localhost:7654/api/auth/password/register \
-H "Content-Type: application/json" \
-d '{"email": "[email protected]", "password": "securepassword123"}'
```
**Responses:**
| Status | Meaning |
|--------|---------|
| 201 | Success - returns user + token |
| 400 | Invalid email/password or too short |
| 403 | Registration disabled |
| 409 | Email already registered |
## React Integration
### Registration Form
```tsx
import { useState } from "react";
import { useApp } from "bknd/react";
function RegisterForm({ onSuccess }: { onSuccess?: () => void }) {
const { api } = useApp();
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [confirmPassword, setConfirmPassword] = useState("");
const [error, setError] = useState<string | null>(null);
const [loading, setLoading] = useState(false);
async function handleSubmit(e: React.FormEvent) {
e.preventDefault();
setError(null);
if (password !== confirmPassword) {
setError("Passwords do not match");
return;
}
if (password.length < 8) {
setError("Password must be at least 8 characters");
return;
}
setLoading(true);
const { ok, status } = await api.auth.register("password", {
email,
password,
});
setLoading(false);
if (ok) {
onSuccess?.();
} else if (status === 409) {
setError("Email already registered");
} else {
setError("Registration failed");
}
}
return (
<form onSubmit={handleSubmit}>
{error && <p className="error">{error}</p>}
<input
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="Email"
required
/>
<input
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="Password"
minLength={8}
required
/>
<input
type="password"
value={confirmPassword}
onChange={(e) => setConfirmPassword(e.target.value)}
placeholder="Confirm Password"
required
/>
<button disabled={loading}>
{loading ? "Creating..." : "Create Account"}
</button>
</form>
);
}
```
### Using useAuth Hook
```tsx
import { useAuth } from "@bknd/react";
function RegisterPage() {
const { user, isLoading, register } = useAuth();
if (isLoading) return <div>Loading...</div>;
if (user) return <Navigate to="/dashboard" />;
async function handleRegister(email: string, password: string) {
await register("password", { email, password });
}
return <RegisterForm onSuccess={() => navigate("/dashboard")} />;
}
```
## Custom Fields After Registration
Registration only accepts `email` and `password`. Add custom fields after:
```typescript
// 1. Extend users entity
const schema = em({
users: entity("users", {
email: text().required().unique(),
name: text(),
avatar: text(),
}),
});
// 2. Update user after registration
const { data } = await api.auth.register("password", { email, password });
await api.data.updateOne("users", data.user.id, {
name: "John Doe",
avatar: "https://...",
});
```
## Invite-Only Apps
Disable public registration:
```typescript
{
auth: {
allow_register: false, // Disable self-registration
},
}
// Admin creates users via seed or plugin
await app.module.auth.createUser({
email: "[email protected]",
password: tempPassword,
role: "user",
});
```
## Common Pitfalls
### Registration Disabled
**Problem:** `Registration not allowed` (403)
**Fix:** `{ auth: { allow_register: true } }`
### Role Not Found
**Problem:** `Role "user" not found`
**Fix:** Define role before using:
```typescript
{
auth: {
roles: { user: { implicit_allow: false } },
default_role_register: "user",
},
}
```
### User Already Exists
**Problem:** 409 error
**Fix:** Handle gracefully:
```tsx
if (status === 409) {
setError("Email already registered. Try logging in instead.");
}
```
### Token Not Stored
**Problem:** User not logged in after registration
**Fix:** Provide storage:
```typescript
const api = new Api({
host: "http://localhost:7654",
storage: localStorage, // Required for persistence
});
```
### Custom Fields Ignored
**Problem:** Extra fields passed to registration not saved
**Cause:** Registration only accepts email/password
**Fix:** Update user after registration (see Custom Fields section)
## Verification
```bash
# 1. Test registration
curl -X POST http://localhost:7654/api/auth/password/register \
-H "Content-Type: application/json" \
-d '{"email": "[email protected]", "password": "password123"}'
# 2. Verify token works
curl http://localhost:7654/api/auth/me \
-H "Authorization: Bearer <token>"
```
## DOs and DON'Ts
**DO:**
- Use bcrypt hashing in production
- Validate password length client-side to match server config
- Handle 409 error with login suggestion
- Store token with `storage: localStorage`
- Define roles before using `default_role_register`
**DON'T:**
- Use `hashing: "plain"` in production
- Expect custom fields in registration payload
- Forget to handle registration errors
- Disable registration without alternative user creation
## Related Skills
- **bknd-setup-auth** - Configure authentication system
- **bknd-create-user** - Programmatic user creation (admin/seed)
- **bknd-login-flow** - Login/logout functionality
- **bknd-password-reset** - Password reset flow
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.