feat: update jwt auth

This commit is contained in:
Steven
2023-08-02 07:29:58 +08:00
parent 759ca1c6fd
commit dfe47b9b7e
9 changed files with 121 additions and 235 deletions

View File

@ -8,6 +8,7 @@ import (
"net/url"
"strings"
"github.com/boojack/slash/api/auth"
"github.com/boojack/slash/store"
"github.com/labstack/echo/v4"
"github.com/pkg/errors"
@ -31,7 +32,7 @@ func (s *APIV1Service) registerRedirectorRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("not found shortcut with name: %s", shortcutName))
}
if shortcut.Visibility != store.VisibilityPublic {
userID, ok := c.Get(getUserIDContextKey()).(int)
userID, ok := c.Get(auth.UserIDContextKey).(int)
if !ok {
return echo.NewHTTPError(http.StatusUnauthorized, "Unauthorized")
}