fix(auth): 修复历史分销用户登录后立即退出

This commit is contained in:
yml
2026-11-17 16:15:00 +08:00
parent 4be9f28e36
commit a6eb6c95b9
8 changed files with 161 additions and 5 deletions
+12
View File
@@ -27,6 +27,7 @@ const LegacyHeaderName = "X-Site-Code"
type tenantScopeContextKey struct{}
type domainScopeContextKey struct{}
type boundSiteCodeContextKey struct{}
// WithTenantScope 标记当前请求已识别为经营租户。
// 经营租户与历史分销站点使用不同归属模型,识别成功后必须忽略旧分销站点编码。
@@ -50,6 +51,17 @@ func HasDomainScope(ctx context.Context) bool {
return enabled
}
// WithBoundSiteCode 记录本次请求已绑定的历史分销站点编码。
// 与请求头不同,该值位于服务端上下文,可供鉴权校验用户是否属于本站。
func WithBoundSiteCode(ctx context.Context, code string) context.Context {
return context.WithValue(ctx, boundSiteCodeContextKey{}, strings.TrimSpace(code))
}
func BoundSiteCodeFromContext(ctx context.Context) string {
code, _ := ctx.Value(boundSiteCodeContextKey{}).(string)
return strings.TrimSpace(code)
}
// FromRequest 按权威优先级解析站点编码:
// X-Distribution-Site-Code 头 → X-Site-Code 旧头 → distribution_site_code / site_code query。
// 所有来源均做 TrimSpace,返回空串表示主站。经营租户请求始终返回空串,