the following is the function used by the backend to generate jwt-token (written by golang), which returns jwt-token to the front end, including username:
// Sign signs the context with the specified secret.
func Sign(ctx *gin.Context, c Context, secret string) (tokenString string, err error) {
// Load the jwt secret from the Gin config if the secret isn"t specified.
if secret == "" {
secret = viper.GetString("jwt_secret")
}
// The token content.
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"id": c.ID,
"username": c.Username,
"nbf": time.Now().Unix(),
"iat": time.Now().Unix(),
})
// Sign the token with the specified secret.
tokenString, err = token.SignedString([]byte(secret))
return
}
question:
the front-end javascript receives the jwt-token, how to resolve the username in the jwt-token?