Skip to content

Commit

Permalink
Added jwtclaimsreader
Browse files Browse the repository at this point in the history
  • Loading branch information
svera committed Apr 22, 2024
1 parent 301ff9c commit 3f18c9e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions internal/webserver/jwtclaimsreader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package webserver

import (
"github.com/gofiber/fiber/v2"
"github.com/golang-jwt/jwt/v4"
"github.com/svera/coreander/v3/internal/webserver/model"
)

func sessionData(c *fiber.Ctx) model.User {
var user model.User
if t, ok := c.Locals("user").(*jwt.Token); ok {
claims := t.Claims.(jwt.MapClaims)
userDataMap := claims["userdata"].(map[string]interface{})
if value, ok := userDataMap["ID"].(float64); ok {
user.ID = uint(value)
}
if value, ok := userDataMap["Name"].(string); ok {
user.Name = value
}
if value, ok := userDataMap["Username"].(string); ok {
user.Username = value
}
if value, ok := userDataMap["Email"].(string); ok {
user.Email = value
}
if value, ok := userDataMap["Role"].(float64); ok {
user.Role = int(value)
}
if value, ok := userDataMap["Uuid"].(string); ok {
user.Uuid = value
}
if value, ok := userDataMap["SendToEmail"].(string); ok {
user.SendToEmail = value
}
if value, ok := userDataMap["WordsPerMinute"].(float64); ok {
user.WordsPerMinute = value
}
}

return user
}

0 comments on commit 3f18c9e

Please sign in to comment.