Files
metabuilder/packages/ui_auth/seed/scripts/gate/wrap.lua
2025-12-30 12:45:27 +00:00

33 lines
720 B
Lua

-- Wrap content with auth gate
local check_module = require("gate.check")
---@class GateContext
---@field user? table
---@field requiredLevel? number
---@field children? table
---@class UIComponent
---@field type string
---@field props? table
local M = {}
---Wrap content with authentication/authorization gate
---@param ctx GateContext
---@return UIComponent|table
function M.wrap(ctx)
local result = check_module.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