修复 无法获取用户的问题
This commit is contained in:
parent
574d25691c
commit
c2b8d0e654
@ -2,7 +2,6 @@ package providers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"framework_v2/internal/consts"
|
"framework_v2/internal/consts"
|
||||||
"framework_v2/internal/helper"
|
"framework_v2/internal/helper"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@ -21,7 +20,7 @@ const AnonymousUser = "anonymous"
|
|||||||
|
|
||||||
func MiddlewareJWTAuth(c *gin.Context) {
|
func MiddlewareJWTAuth(c *gin.Context) {
|
||||||
var sub = AnonymousUser
|
var sub = AnonymousUser
|
||||||
var jwtIdToken = consts.UserTokenInfo{}
|
var jwtIdToken = &consts.UserTokenInfo{}
|
||||||
|
|
||||||
if Config.DebugMode.Enable {
|
if Config.DebugMode.Enable {
|
||||||
jwtIdToken.Sub = sub
|
jwtIdToken.Sub = sub
|
||||||
@ -62,8 +61,6 @@ func MiddlewareJWTAuth(c *gin.Context) {
|
|||||||
helper.ResponseError(c, http.StatusUnauthorized, ErrNotValidToken)
|
helper.ResponseError(c, http.StatusUnauthorized, ErrNotValidToken)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("test", jwtIdToken.Sub)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Set(consts.UserTokenInfoKey, jwtIdToken)
|
c.Set(consts.UserTokenInfoKey, jwtIdToken)
|
||||||
|
@ -52,7 +52,7 @@ func ParseJWT(jwtB64 string) (*jwt.Token, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetAuthFromCtx(ctx context.Context) *consts.UserTokenInfo {
|
func GetAuthFromCtx(ctx context.Context) *consts.UserTokenInfo {
|
||||||
auth := ctx.Value("auth")
|
auth := ctx.Value(consts.UserTokenInfoKey)
|
||||||
|
|
||||||
if auth == nil {
|
if auth == nil {
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user