Loading...
Loading...
Use when encountering Bknd errors, getting error messages, something not working, or needing quick fixes. Covers error code reference, quick solutions, and common mistake patterns.
npx skill4agent add cameronapak/bknd-skills bknd-troubleshoot# Check JSON validity
echo '{"title":"Test"}' | jq .
# Verify Content-Type header
curl -X POST http://localhost:3000/api/data/posts \
-H "Content-Type: application/json" \
-d '{"title":"Test"}'Content-Type: application/json// Check token exists
console.log(localStorage.getItem("bknd_token"));
// Verify token with /me endpoint
const me = await api.auth.me();
console.log(me.ok ? "Valid" : "Invalid/expired");storage: localStorageexpiresBearer <token>credentials: "include"const api = new Api({
host: "http://localhost:3000",
storage: localStorage, // Required for token persistence
});# Check user's role
curl http://localhost:3000/api/auth/me \
-H "Authorization: Bearer <token>"auth: {
guard: {
enabled: true,
roles: {
user: {
permissions: [
"data.entity.read",
"data.entity.create", // Add missing permission
]
}
}
}
}# List available routes
npx bknd debug routes
# List entities
curl http://localhost:3000/api/data
# Check entity name case (must match exactly)
curl http://localhost:3000/api/data/posts # lowercasePostsposts/api/auth/login/api/auth/password/login// Check for existing record before create
const exists = await api.data.readOneBy("users", { email });
if (!exists.ok) {
await api.data.createOne("users", { email, ... });
}media: {
body_max_size: 50 * 1024 * 1024, // 50MB
}# Check server logs for stack trace
# Look for error details in response body
curl http://localhost:3000/api/data/posts 2>&1 | jq .errorconst schema = em({
posts: entity("posts", { title: text() }),
});
schema.repo("posts").find(); // Error!// em() is for schema definition only
const schema = em({
posts: entity("posts", { title: text() }),
});
// Use SDK for queries
const api = new Api({ host: "http://localhost:3000" });
await api.data.readMany("posts");POST /api/auth/login # 404
POST /api/auth/register # 404POST /api/auth/password/login # For password strategy
POST /api/auth/password/register
POST /api/auth/google/login # For Google OAuthconst api = new Api({
host: "http://localhost:3000",
});const api = new Api({
host: "http://localhost:3000",
storage: localStorage, // Or sessionStorage
});import { enum } from "bknd"; // Syntax error - reserved wordimport { enumm } from "bknd";
entity("posts", {
status: enumm(["draft", "published"]),
});import { primary } from "bknd"; // Not exported in v0.20.0// Primary keys are auto-generated
// To customize format:
entity("posts", { title: text() }, { primary_format: "uuid" });permissions: [{
permission: "data.entity.read",
filter: { user_id: { $eq: "@user.id" } }, // Wrong prefix
}]permissions: [{
permission: "data.entity.read",
filter: { user_id: { $eq: "@auth.user.id" } }, // Correct prefix
}]npx bknd run --memory
# Or config: { url: ":memory:" }npx bknd run --db-url "file:data.db"
# Or config: { url: "file:data.db" }auth: {
guard: {
roles: { ... } // Guard not enabled!
}
}auth: {
guard: {
enabled: true, // Required!
roles: { ... }
}
}// Server config
server: {
cors: {
origin: ["http://localhost:5173"],
credentials: true,
}
}
auth: {
cookie: {
secure: false, // false for HTTP dev
sameSite: "lax", // Not "strict" for OAuth
}
}
// Client fetch
fetch(url, { credentials: "include" });permissions: [{
permission: "data.entity.read",
effect: "allow", // Won't filter!
condition: { user_id: { $eq: "@auth.user.id" } },
}]permissions: [{
permission: "data.entity.read",
effect: "filter", // Filters results
filter: { user_id: { $eq: "@auth.user.id" } },
}]curl http://localhost:3000/api/datanpx bknd debug routesnpx bknd debug paths# Login
curl -X POST http://localhost:3000/api/auth/password/login \
-H "Content-Type: application/json" \
-d '{"email":"test@example.com","password":"password"}'
# Check token
curl http://localhost:3000/api/auth/me \
-H "Authorization: Bearer <token>"# Unauthenticated
curl http://localhost:3000/api/data/posts
# Authenticated
curl http://localhost:3000/api/data/posts \
-H "Authorization: Bearer <token>"curl http://localhost:3000/api/system/schema| Issue | Solution |
|---|---|
| Config not loading | Check file name: |
| Port in use | |
| Types outdated | |
| Hot reload not working | Restart server |
| Issue | Solution |
|---|---|
| JWT errors | Set |
| Cookie not set | |
| 500 errors | Check logs, set |
| D1 not found | Check wrangler.json bindings |
| Issue | Solution |
|---|---|
| Cold start slow | Use edge-compatible DB (D1, Turso) |
| File upload fails | Use S3/R2, not local storage |
| SQLite native error | Use LibSQL or PostgreSQL |
# Check file exists
ls bknd.config.*
# Specify explicitly
npx bknd run -c ./bknd.config.ts# Find process
lsof -i :3000
# Use different port
npx bknd run --port 3001# Headless server - disable browser open
npx bknd run --no-open# Check for memory mode in output
# Use file database
npx bknd run --db-url "file:data.db""type": "module".mjs// SDK client
import { Api } from "bknd/client";
// Schema builders
import { em, entity, text } from "bknd";
// Adapters
import { serve } from "bknd/adapter/node"; // Node
import { serve } from "bknd/adapter/cloudflare"; // CF Workersnpx bknd debug routesem():memory:storage: localStorageenabled: true@user.id@auth.user.id