修复 无法获取用户的问题

This commit is contained in:
Twilight 2024-06-13 19:16:25 +08:00
parent 574d25691c
commit c2b8d0e654
2 changed files with 2 additions and 5 deletions

View File

@ -2,7 +2,6 @@ package providers
import (
"errors"
"fmt"
"framework_v2/internal/consts"
"framework_v2/internal/helper"
"github.com/gin-gonic/gin"
@ -21,7 +20,7 @@ const AnonymousUser = "anonymous"
func MiddlewareJWTAuth(c *gin.Context) {
var sub = AnonymousUser
var jwtIdToken = consts.UserTokenInfo{}
var jwtIdToken = &consts.UserTokenInfo{}
if Config.DebugMode.Enable {
jwtIdToken.Sub = sub
@ -62,8 +61,6 @@ func MiddlewareJWTAuth(c *gin.Context) {
helper.ResponseError(c, http.StatusUnauthorized, ErrNotValidToken)
return
}
fmt.Println("test", jwtIdToken.Sub)
}
c.Set(consts.UserTokenInfoKey, jwtIdToken)

View File

@ -52,7 +52,7 @@ func ParseJWT(jwtB64 string) (*jwt.Token, error) {
}
func GetAuthFromCtx(ctx context.Context) *consts.UserTokenInfo {
auth := ctx.Value("auth")
auth := ctx.Value(consts.UserTokenInfoKey)
if auth == nil {
return nil