go-zero
go-zero copied to clipboard
Token confusion.
Describe the bug A clear and concise description of what the bug is.
To Reproduce Steps to reproduce the behavior, if applicable:
-
The code is
func (m *OplogMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { body := "" if r.Method == http.MethodPost { bf := bytes.NewBuffer(nil) wt := bufio.NewWriter(bf) io.Copy(wt, r.Body) rb, _ := io.ReadAll(bf) r.Body = io.NopCloser(bytes.NewBuffer(rb)) body = string(rb) }
next(w, r)
if len(r.Header.Get("Authorization")) > 0 {
ut, _ := jwtx.GetUserType(r.Context())
deptLv := permissions.GetDeptLvl(r.Context(), m.Redis)
shopUniqueKey := ""
//门店用户
if deptLv == "3" {
shopUniqueKeys := permissions.GetShopsUniqueKey(r.Context(), m.Redis)
if len(shopUniqueKeys) > 0 {
shopUniqueKey = shopUniqueKeys[0]
}
}
m.OplogRpc.AddSysLog(r.Context(), &oplog.AddSysLogRequest{
Info: &oplog.SysLog{
UserUniqueKey: jwtx.GetUID(r.Context()),
UserName: jwtx.GetUserName(r.Context()),
ShopUniqueKey: shopUniqueKey,
Ip: tool.GetRemoteClientIp(r),
Uri: r.RequestURI,
Method: r.Method,
Type: ut,
Request: body,
},
})
}
}
}
2. The error is
The token obtained from the header belongs to someone else.
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Environments (please complete the following information):**
- OS: [e.g. Linux]
- go-zero version [e.g. 1.2.1]
- goctl version [e.g. 1.2.1, optional]
**More description**
Add any other context about the problem here.