jwt 认证

This commit is contained in:
eson
2023-06-06 20:08:32 +08:00
parent ab9df9bc42
commit 48be41f64b
11 changed files with 192 additions and 44 deletions

View File

@@ -35,8 +35,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
)
server.AddRoutes(
[]rest.Route{
{
@@ -46,6 +44,5 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
},
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
)
}

View File

@@ -2,6 +2,7 @@ package handler
import (
"errors"
"fmt"
"net/http"
"github.com/zeromicro/go-zero/core/logx"
@@ -10,6 +11,7 @@ import (
"fusenapi/home-user-auth/internal/logic"
"fusenapi/home-user-auth/internal/svc"
"fusenapi/home-user-auth/internal/types"
"fusenapi/utils/basic"
)
func UserLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
@@ -25,7 +27,10 @@ func UserLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
l := logic.NewUserLoginLogic(r.Context(), svcCtx)
resp := l.UserLogin(&req)
resp, token := l.UserLogin(&req)
if resp.Code == basic.CodeOK.Code {
w.Header().Add("Authorization", fmt.Sprintf("Bearer %s", token))
}
if resp != nil {
httpx.OkJsonCtx(r.Context(), w, resp)
} else {