feat: 修改jwt逻辑,登出黑名单处理

This commit is contained in:
Blizzard
2025-09-15 21:00:39 +08:00
parent 9be75d53fe
commit 6beb915adf
9 changed files with 74 additions and 64 deletions
+26
View File
@@ -0,0 +1,26 @@
package system
import (
"context"
"sundynix-go/global"
"sundynix-go/utils"
)
type JwtService struct{}
var JwtServiceApp = new(JwtService)
// 登出,禁用jwt
func (s JwtService) PutBlacklist(userId string, token string) (err error) {
expire, err := utils.ParseDuration(global.Config.JWT.ExpiresTime)
if err != nil {
return err
}
err = global.Redis.Set(context.Background(), userId, token, expire).Err()
return err
}
func (s JwtService) IsInBlacklist(userId string, token string) bool {
val, err := global.Redis.Get(context.Background(), userId).Result()
return err == nil && val == token
}