After setup a simple has many association where user has_many posts to create a post with user ID seems that is necessary parse the jwt Claims to get the userID and place it on Post creation.
So, how to get the user ID from jwt Claims
i tried parse the token but just show up
map[email:teste@teste.com exp:1.655701949e+09 username:teste]
tokenString := c.GetHeader("Authorization")
//
claims := jwt.MapClaims{}
token, err := jwt.ParseWithClaims(tokenString, claims, func(token *jwt.Token) (interface{}, error) {
return []byte("supersecretkey"), nil
})
if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
fmt.Printf("%v", claims )
} else {
fmt.Println(err)
}