fix admin redirection on default role matched only

This commit is contained in:
dswbx
2025-01-14 11:55:24 +01:00
parent a9b2c613e1
commit c7bd0a636b
2 changed files with 58 additions and 1 deletions

View File

@@ -1,4 +1,7 @@
import { App } from "bknd";
import { serve } from "bknd/adapter/nextjs";
import { boolean, em, entity, text } from "bknd/data";
import { secureRandomString } from "bknd/utils";
export const config = {
runtime: "edge",
@@ -9,11 +12,60 @@ export const config = {
unstable_allowDynamic: ["**/*.js"]
};
// the em() function makes it easy to create an initial schema
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 default serve({
// we can use any libsql config, and if omitted, uses in-memory
connection: {
type: "libsql",
config: {
url: "http://localhost:8080"
}
},
// an initial config is only applied if the database is empty
initialConfig: {
data: schema.toJSON(),
// we're enabling auth ...
auth: {
enabled: true,
jwt: {
secret: secureRandomString(64)
}
}
},
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: "ds@bknd.io",
password: "12345678"
});
},
"sync"
);
}
});