Files
userbase/examples/nextjs/bknd.config.ts
T
shishantbiswas 0bfcb5ad71
Run Tests / test (pull_request) Successful in 4m57s
bknd is dead long live userbase
2026-09-27 19:34:06 +05:30

75 lines
2.1 KiB
TypeScript

import type { NextjsUserbaseConfig } from "userbase/adapter/nextjs";
import { boolean, em, entity, text } from "userbase";
import { registerLocalMediaAdapter } from "userbase/adapter/node";
import { secureRandomString } from "userbase/utils";
// The local media adapter works well in development, and server based
// deployments. However, on vercel or any other serverless deployments,
// you shouldn't use a filesystem based media adapter.
//
// Additionally, if you run the userbase api on the "edge" runtime,
// this would not work as well.
//
// For production, it is recommended to uncomment the line below.
const local = registerLocalMediaAdapter();
const schema = em({
todos: entity("todos", {
title: text(),
done: boolean(),
}),
});
// register your schema to get automatic type completion
type Database = (typeof schema)["DB"];
declare module "userbase" {
interface DB extends Database {}
}
export default {
app: (env) => ({
connection: {
url: env.DB_URL ?? "file:data.db",
},
}),
// an initial config is only applied if the database is empty
config: {
data: schema.toJSON(),
// we're enabling auth ...
auth: {
enabled: true,
jwt: {
issuer: "userbase-nextjs-example",
secret: secureRandomString(64),
},
cookie: {
pathSuccess: "/ssr",
pathLoggedOut: "/ssr",
},
},
// ... and media
media: {
enabled: true,
adapter: local({
path: "./public/uploads",
}),
},
},
options: {
// the seed option is only executed if the database was empty
seed: async (ctx) => {
// create some entries
await ctx.em.mutator("todos").insertMany([
{ title: "Learn userbase", done: true },
{ title: "Build something cool", done: false },
]);
// and create a user
await ctx.app.module.auth.createUser({
email: "test@userbase.io",
password: "12345678",
});
},
},
} as const satisfies NextjsUserbaseConfig;