From af9655eeaf9c29868d3fd1263a93efb9a43c5020 Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 12 Nov 2023 15:49:00 +0800 Subject: [PATCH] chore: fix user message --- api/v1/jwt.go | 2 +- api/v1/user.go | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/api/v1/jwt.go b/api/v1/jwt.go index d306cd4..545e62f 100644 --- a/api/v1/jwt.go +++ b/api/v1/jwt.go @@ -63,7 +63,7 @@ func JWTMiddleware(s *APIV1Service, next echo.HandlerFunc, secret string) echo.H accessToken := findAccessToken(c) if accessToken == "" { // When the request is not authenticated, we allow the user to access the shortcut endpoints for those public shortcuts. - if util.HasPrefixes(path, "/s/") && method == http.MethodGet { + if util.HasPrefixes(path, "/s/", "/api/v1/user/") && method == http.MethodGet { return next(c) } return echo.NewHTTPError(http.StatusUnauthorized, "Missing access token") diff --git a/api/v1/user.go b/api/v1/user.go index 6ff0014..c516fd4 100644 --- a/api/v1/user.go +++ b/api/v1/user.go @@ -188,7 +188,12 @@ func (s *APIV1Service) registerUserRoutes(g *echo.Group) { return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to find user, err: %s", err)).SetInternal(err) } - return c.JSON(http.StatusOK, convertUserFromStore(user)) + userMessage := convertUserFromStore(user) + userID, ok := c.Get(userIDContextKey).(int32) + if !ok { + userMessage.Email = "" + } + return c.JSON(http.StatusOK, userMessage) }) g.PATCH("/user/:id", func(c echo.Context) error {