feat: 新增获取登录用户信息函数

main
熊二 2 years ago
parent bf7064f992
commit dcaf54a67a
  1. 5
      app/fns.go

@ -101,6 +101,11 @@ var ErrInvalidToken = &Error{
Message: "错误令牌", Message: "错误令牌",
} }
func UserTokenFromContext(ctx context.Context) (*UserToken, bool) {
ut, ok := ctx.Value("USER_TOKEN").(*UserToken)
return ut, ok
}
func CheckAuthToken(next http.Handler) http.Handler { func CheckAuthToken(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
token, _, _ := jwtauth.FromContext(r.Context()) token, _, _ := jwtauth.FromContext(r.Context())

Loading…
Cancel
Save