mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
fix admin redirection on default role matched only
This commit is contained in:
@@ -87,8 +87,13 @@ export class AdminController extends Controller {
|
|||||||
hono.get(
|
hono.get(
|
||||||
authRoutes.login,
|
authRoutes.login,
|
||||||
permission([SystemPermissions.accessAdmin, SystemPermissions.schemaRead], {
|
permission([SystemPermissions.accessAdmin, SystemPermissions.schemaRead], {
|
||||||
|
// @ts-ignore
|
||||||
onGranted: async (c) => {
|
onGranted: async (c) => {
|
||||||
return c.redirect(authRoutes.success);
|
// @todo: add strict test to permissions middleware?
|
||||||
|
if (auth.authenticator.isUserLoggedIn()) {
|
||||||
|
console.log("redirecting to success");
|
||||||
|
return c.redirect(authRoutes.success);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
|
import { App } from "bknd";
|
||||||
import { serve } from "bknd/adapter/nextjs";
|
import { serve } from "bknd/adapter/nextjs";
|
||||||
|
import { boolean, em, entity, text } from "bknd/data";
|
||||||
|
import { secureRandomString } from "bknd/utils";
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
runtime: "edge",
|
runtime: "edge",
|
||||||
@@ -9,11 +12,60 @@ export const config = {
|
|||||||
unstable_allowDynamic: ["**/*.js"]
|
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({
|
export default serve({
|
||||||
|
// we can use any libsql config, and if omitted, uses in-memory
|
||||||
connection: {
|
connection: {
|
||||||
type: "libsql",
|
type: "libsql",
|
||||||
config: {
|
config: {
|
||||||
url: "http://localhost:8080"
|
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"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user