new error codes, code refactor, added getMessages function

This commit is contained in:
slawk0
2025-02-07 22:59:36 +01:00
parent 51b426ba54
commit 7342c5b483
9 changed files with 189 additions and 31 deletions

View File

@@ -1,10 +1,13 @@
package middleware
import (
"fmt"
jwtware "github.com/gofiber/contrib/jwt"
"github.com/gofiber/fiber/v2"
"github.com/golang-jwt/jwt/v5"
"github.com/google/uuid"
"os"
"relay-server/helpers"
"relay-server/model"
)
@@ -17,8 +20,11 @@ func Protected() fiber.Handler {
SuccessHandler: func(c *fiber.Ctx) error {
user := c.Locals("user").(*jwt.Token)
claims := user.Claims.(*model.UserClaims)
c.Locals("userID", claims.UserID)
userID, err := uuid.Parse(claims.UserID)
if err != nil {
return helpers.NewError(helpers.ErrInternal, "internal server error", fmt.Errorf("failed to parse user ID: %w", err))
}
c.Locals("userID", userID)
c.Locals("username", claims.Username)
return c.Next()
},