feat: JWT Claims 新增资产字段,登录 token 携带当前资产上下文
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -90,6 +90,8 @@ func (m *PersonalAuthMiddleware) Authenticate() fiber.Handler {
|
||||
|
||||
c.Locals("customer_id", claims.CustomerID)
|
||||
c.Locals("customer_phone", claims.Phone)
|
||||
c.Locals("customer_asset_type", claims.AssetType)
|
||||
c.Locals("customer_asset_id", claims.AssetID)
|
||||
c.Locals("skip_owner_filter", true)
|
||||
|
||||
m.logger.Debug("个人客户认证成功",
|
||||
@@ -113,3 +115,11 @@ func GetCustomerPhone(c *fiber.Ctx) (string, bool) {
|
||||
phone, ok := c.Locals("customer_phone").(string)
|
||||
return phone, ok
|
||||
}
|
||||
|
||||
// GetCurrentAsset 从 context 中获取当前登录所用的资产类型和 ID
|
||||
func GetCurrentAsset(c *fiber.Ctx) (assetType string, assetID uint, ok bool) {
|
||||
assetType, _ = c.Locals("customer_asset_type").(string)
|
||||
assetID, _ = c.Locals("customer_asset_id").(uint)
|
||||
ok = assetType != "" && assetID != 0
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user