package common

import "github.com/gin-gonic/gin"

// GetGinUser 从 Gin context 中提取当前登录用户的 uid 和 role
// 如果用户未登录，ok 返回 false；role 可能为空字符串
func GetGinUser(c *gin.Context) (uid uint, role string, ok bool) {
	if v, exists := c.Get("uid"); exists {
		if u, isUint := v.(uint); isUint {
			uid = u
			ok = true
		}
	}
	if v, exists := c.Get("role"); exists {
		if r, isStr := v.(string); isStr {
			role = r
		}
	}
	return
}
