Skip to content

Commit

Permalink
去除 jwt 错误
Browse files Browse the repository at this point in the history
  • Loading branch information
snowlyg committed Dec 27, 2021
1 parent baf6a54 commit 6e595d7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
10 changes: 5 additions & 5 deletions jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (ra *JwtAuth) GenerateToken(claims *MultiClaims) (string, int64, error) {

// GetTokenByClaims 获取用户信息
func (ra *JwtAuth) GetTokenByClaims(cla *MultiClaims) (string, error) {
return "", ErrJwtNotSuportThisFunc
return "", nil
}

// GetMultiClaims 获取用户信息
Expand All @@ -64,22 +64,22 @@ func (ra *JwtAuth) GetMultiClaims(tokenString string) (*MultiClaims, error) {

// SetUserTokenMaxCount 最大登录限制
func (ra *JwtAuth) SetUserTokenMaxCount(tokenMaxCount int64) error {
return ErrJwtNotSuportThisFunc
return nil
}

//UpdateUserTokenCacheExpire 更新过期时间
func (ra *JwtAuth) UpdateUserTokenCacheExpire(token string) error {
return ErrJwtNotSuportThisFunc
return nil
}

// DelUserTokenCache 删除token缓存
func (ra *JwtAuth) DelUserTokenCache(token string) error {
return ErrJwtNotSuportThisFunc
return nil
}

// CleanUserTokenCache 清空token缓存
func (ra *JwtAuth) CleanUserTokenCache(authorityType int, userId string) error {
return ErrJwtNotSuportThisFunc
return nil
}

// IsAdmin
Expand Down
14 changes: 6 additions & 8 deletions jwt_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package multi

import (
"errors"
"fmt"
"testing"
"time"
Expand Down Expand Up @@ -82,8 +81,8 @@ func TestJwtDelUserTokenCache(t *testing.T) {
t.Error("generate token is empty")
}
err := jwtAuth.DelUserTokenCache(token)
if !errors.Is(err, ErrJwtNotSuportThisFunc) {
t.Errorf("get token by claims token want %v but get %v", ErrJwtNotSuportThisFunc, err)
if err != nil {
t.Errorf("get token by claims token want %v but get %v", nil, err)
}

})
Expand All @@ -92,8 +91,8 @@ func TestJwtDelUserTokenCache(t *testing.T) {
func TestJwtSetUserTokenMaxCount(t *testing.T) {
t.Run("test redis set user token max count", func(t *testing.T) {
err := jwtAuth.SetUserTokenMaxCount(3)
if !errors.Is(err, ErrJwtNotSuportThisFunc) {
t.Errorf("get token by claims token want %v but get %v", ErrJwtNotSuportThisFunc, err)
if err != nil {
t.Errorf("get token by claims token want %v but get %v", nil, err)
}
})
}
Expand Down Expand Up @@ -132,9 +131,8 @@ func TestJwtGetMultiClaims(t *testing.T) {
func TestJwtGetTokenByClaims(t *testing.T) {
t.Run("test get token by claims", func(t *testing.T) {
_, err := jwtAuth.GetTokenByClaims(jwtClaims)

if !errors.Is(err, ErrJwtNotSuportThisFunc) {
t.Errorf("get token by claims token want %v but get %v", ErrJwtNotSuportThisFunc, err)
if err != nil {
t.Errorf("get token by claims token want %v but get %v", nil, err)
}
})

Expand Down
7 changes: 3 additions & 4 deletions multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ var (

// 错误类型
var (
ErrTokenInvalid = errors.New("TOKEN不可用")
ErrEmptyToken = errors.New("TOKEN为空")
ErrOverMaxTokenCount = errors.New("已达到同时登录设备上限")
ErrJwtNotSuportThisFunc = errors.New("JWT验证不支持次方法")
ErrTokenInvalid = errors.New("TOKEN不可用")
ErrEmptyToken = errors.New("TOKEN为空")
ErrOverMaxTokenCount = errors.New("已达到同时登录设备上限")
)

// 授权角色类型
Expand Down

0 comments on commit 6e595d7

Please sign in to comment.