mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
updated nextjs example
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { type NextjsBkndConfig, getApp as getBkndApp } from "bknd/adapter/nextjs";
|
||||
import { App } from "bknd";
|
||||
import { boolean, em, entity, text } from "bknd/data";
|
||||
import { registerLocalMediaAdapter } from "bknd/adapter/node";
|
||||
import { secureRandomString } from "bknd/utils";
|
||||
import { headers } from "next/headers";
|
||||
|
||||
// The local media adapter works well in development, and server based
|
||||
@@ -12,10 +15,71 @@ import { headers } from "next/headers";
|
||||
// For production, it is recommended to uncomment the line below.
|
||||
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 "bknd/core" {
|
||||
interface DB extends Database {}
|
||||
}
|
||||
|
||||
export const config = {
|
||||
connection: {
|
||||
url: process.env.DB_URL as string,
|
||||
authToken: process.env.DB_TOKEN as string,
|
||||
url: "file:data.db",
|
||||
},
|
||||
// an initial config is only applied if the database is empty
|
||||
initialConfig: {
|
||||
data: schema.toJSON(),
|
||||
// we're enabling auth ...
|
||||
auth: {
|
||||
enabled: true,
|
||||
jwt: {
|
||||
issuer: "bknd-nextjs-example",
|
||||
secret: secureRandomString(64),
|
||||
},
|
||||
cookie: {
|
||||
pathSuccess: "/ssr",
|
||||
pathLoggedOut: "/ssr",
|
||||
},
|
||||
},
|
||||
// ... and media
|
||||
media: {
|
||||
enabled: true,
|
||||
adapter: {
|
||||
type: "local",
|
||||
config: {
|
||||
path: "./public",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
options: {
|
||||
// the seed option is only executed if the database was empty
|
||||
seed: async (ctx) => {
|
||||
await ctx.em.mutator("todos").insertMany([
|
||||
{ title: "Learn bknd", done: true },
|
||||
{ title: "Build something cool", done: false },
|
||||
]);
|
||||
},
|
||||
},
|
||||
// here we can hook into the app lifecycle events ...
|
||||
beforeBuild: async (app) => {
|
||||
app.emgr.onEvent(
|
||||
App.Events.AppFirstBoot,
|
||||
async () => {
|
||||
// ... to create an initial user
|
||||
await app.module.auth.createUser({
|
||||
email: "test@bknd.io",
|
||||
password: "12345678",
|
||||
});
|
||||
},
|
||||
"sync",
|
||||
);
|
||||
},
|
||||
} as const satisfies NextjsBkndConfig;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user