Files
sundynix-plant-be/service/system/sys_jwt.go
T
2026-02-14 11:38:59 +08:00

27 lines
617 B
Go

package system
import (
"context"
"sundynix-go/global"
"sundynix-go/utils/timer"
)
type JwtService struct{}
var JwtServiceApp = new(JwtService)
// 登出,禁用jwt
func (s *JwtService) PutBlacklist(userId string, token string) (err error) {
expire, err := timer.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
}