mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-05-04 18:54:53 +00:00
26 lines
666 B
Lua
26 lines
666 B
Lua
local check = require("check")
|
|
local M = {}
|
|
|
|
function M.check(ctx)
|
|
if not ctx.user then
|
|
return { allowed = false, reason = "not_authenticated", redirect = "/login" }
|
|
end
|
|
if ctx.requiredLevel and not check.can_access(ctx.user, ctx.requiredLevel) then
|
|
return { allowed = false, reason = "insufficient_permission" }
|
|
end
|
|
return { allowed = true }
|
|
end
|
|
|
|
function M.wrap(ctx)
|
|
local result = M.check(ctx)
|
|
if not result.allowed then
|
|
if result.redirect then
|
|
return { type = "Redirect", props = { to = result.redirect } }
|
|
end
|
|
return { type = "AccessDenied", props = { reason = result.reason } }
|
|
end
|
|
return ctx.children
|
|
end
|
|
|
|
return M
|