This commit is contained in:
vipg
2026-02-09 17:43:42 +08:00
parent 25c4628b5f
commit c7b11dca35
5 changed files with 83 additions and 22 deletions

View File

@@ -28,7 +28,7 @@ func (h *Handler) Register(w http.ResponseWriter, r *http.Request) {
httpx.BadRequest(w, "invalid json")
return
}
userID, err := h.S.Register(req.Account, req.Password)
userID, token, err := h.S.Register(req.Account, req.Password)
if err != nil {
switch err {
case service.ErrInvalidInput:
@@ -40,7 +40,7 @@ func (h *Handler) Register(w http.ResponseWriter, r *http.Request) {
}
return
}
httpx.Created(w, map[string]string{"user_id": userID})
httpx.Created(w, map[string]string{"user_id": userID, "token": token})
}
func (h *Handler) Login(w http.ResponseWriter, r *http.Request) {
@@ -53,7 +53,7 @@ func (h *Handler) Login(w http.ResponseWriter, r *http.Request) {
httpx.BadRequest(w, "invalid json")
return
}
userID, err := h.S.Login(req.Account, req.Password)
userID, token, err := h.S.Login(req.Account, req.Password)
if err != nil {
switch err {
case service.ErrInvalidInput:
@@ -65,7 +65,7 @@ func (h *Handler) Login(w http.ResponseWriter, r *http.Request) {
}
return
}
httpx.OK(w, map[string]string{"user_id": userID})
httpx.OK(w, map[string]string{"user_id": userID, "token": token})
}
func (h *Handler) Healthz(w http.ResponseWriter, r *http.Request) {