From c5a32c68a5952567be4d248af1d0ec016d13aba6 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Fri, 12 Apr 2024 15:43:00 -0700 Subject: [PATCH] login now returns json with token info --- api/domain/responses.go | 7 +++++++ api/handlers/v1/auth.go | 9 +++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/api/domain/responses.go b/api/domain/responses.go index 445e05c..dce4b9a 100644 --- a/api/domain/responses.go +++ b/api/domain/responses.go @@ -1,5 +1,12 @@ package domain +type LoginResponse struct { + Success bool `json:"success"` + Token string `json:"token"` + Type string `json:"type"` + RefreshToken string `json:"refreshToken"` +} + type ErrorResponse struct { Success bool `json:"success"` Message string `json:"message"` diff --git a/api/handlers/v1/auth.go b/api/handlers/v1/auth.go index 6c66cdd..209903c 100644 --- a/api/handlers/v1/auth.go +++ b/api/handlers/v1/auth.go @@ -4,8 +4,8 @@ import ( "errors" "net/http" - "git.jamestombleson.com/jtom38/go-cook/api/repositories" "git.jamestombleson.com/jtom38/go-cook/api/domain" + "git.jamestombleson.com/jtom38/go-cook/api/repositories" "github.com/golang-jwt/jwt/v5" "github.com/labstack/echo/v4" @@ -89,7 +89,12 @@ func (h *Handler) AuthLogin(c echo.Context) error { return h.InternalServerErrorResponse(c, err.Error()) } - return c.JSON(http.StatusOK, token) + return c.JSON(http.StatusOK, domain.LoginResponse{ + Success: true, + Token: token, + Type: "Bearer", + RefreshToken: "", + }) } func (h *Handler) validateAdminToken(c echo.Context, password string) error {