🐛 Fix on reading jwt claims

This commit is contained in:
2024-10-30 23:59:04 +08:00
parent f9b6cd2e20
commit 3f6ea11d22
4 changed files with 12 additions and 4 deletions

View File

@ -31,6 +31,6 @@ func tokenRead(in string) (*sec.JwtClaims, error) {
return nil, nil
}
claims, err := sec.ReadJwt[sec.JwtClaims](JReader, in)
return &claims, err
claims, err := sec.ReadJwt[*sec.JwtClaims](JReader, in, &sec.JwtClaims{})
return claims, err
}

View File

@ -9,6 +9,7 @@ import (
"git.solsynth.dev/hypernet/nexus/pkg/proto"
"github.com/gofiber/fiber/v2"
"github.com/rs/zerolog/log"
"strconv"
"time"
)
@ -26,8 +27,12 @@ func userinfoFetch(c *fiber.Ctx) error {
} else {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
sed, err := strconv.Atoi(claims.Session)
if err != nil {
return fiber.NewError(fiber.StatusUnauthorized, fmt.Sprintf("invalid token payload"))
}
resp, err := proto.NewAuthServiceClient(conn).Authenticate(ctx, &proto.AuthRequest{
SessionId: uint64(claims.Session),
SessionId: uint64(sed),
})
if err != nil {
return fiber.NewError(fiber.StatusUnauthorized, fmt.Sprintf("unable to load userinfo: %v", err))