From d817cb0ffd4ad9c540a36b358c71c081e800920b Mon Sep 17 00:00:00 2001 From: chao <48119764+withchao@users.noreply.github.com> Date: Fri, 1 Aug 2025 10:48:25 +0800 Subject: [PATCH] fix: admin token in standalone mode (#3499) * fix: performance issues with Kafka caused by encapsulating the MQ interface * fix: admin token in standalone mode --- internal/api/router.go | 5 +++++ pkg/common/storage/cache/redis/token.go | 9 ++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/api/router.go b/internal/api/router.go index 8a4199581..1d3a92dd7 100644 --- a/internal/api/router.go +++ b/internal/api/router.go @@ -97,6 +97,11 @@ func newGinRouter(ctx context.Context, client discovery.SvcDiscoveryRegistry, cf case BestSpeed: r.Use(gzip.Gzip(gzip.BestSpeed)) } + if config.Standalone() { + r.Use(func(c *gin.Context) { + c.Set(authverify.CtxAdminUserIDsKey, cfg.Share.IMAdminUser.UserIDs) + }) + } r.Use(api.GinLogger(), prommetricsGin(), gin.RecoveryWithWriter(gin.DefaultErrorWriter, mw.GinPanicErr), mw.CorsHandler(), mw.GinParseOperationID(), GinParseToken(rpcli.NewAuthClient(authConn)), setGinIsAdmin(cfg.Share.IMAdminUser.UserIDs)) diff --git a/pkg/common/storage/cache/redis/token.go b/pkg/common/storage/cache/redis/token.go index b3870daee..c74ccce66 100644 --- a/pkg/common/storage/cache/redis/token.go +++ b/pkg/common/storage/cache/redis/token.go @@ -165,16 +165,15 @@ func (c *tokenCache) DeleteTokenByTokenMap(ctx context.Context, userID string, t } func (c *tokenCache) DeleteAndSetTemporary(ctx context.Context, userID string, platformID int, fields []string) error { - key := cachekey.GetTokenKey(userID, platformID) - if err := c.rdb.HDel(ctx, key, fields...).Err(); err != nil { - return errs.Wrap(err) - } for _, f := range fields { k := cachekey.GetTemporaryTokenKey(userID, platformID, f) if err := c.rdb.Set(ctx, k, "", time.Minute*5).Err(); err != nil { return errs.Wrap(err) } } - + key := cachekey.GetTokenKey(userID, platformID) + if err := c.rdb.HDel(ctx, key, fields...).Err(); err != nil { + return errs.Wrap(err) + } return nil }