GenerateToken (utils/jwt.go)

ClawManager · backend/internal/utils/jwt.go · go · MIT
auth

Module exposing: GenerateToken, ValidateToken, TokenClaims

// Source: https://github.com/Yuan-lab-LLM/ClawManager | License: MIT | Copyright 2026 ClawManager contributors
// Provided via justclaw.it.com; keep this notice with the code.
package utils

import (
	"errors"
	"time"

	"github.com/golang-jwt/jwt/v5"
)

// TokenClaims represents JWT token claims
type TokenClaims struct {
	UserID    int    `json:"user_id"`
	TokenType string `json:"token_type"`
	jwt.RegisteredClaims
}

// GenerateToken generates a new JWT token
func GenerateToken(claims TokenClaims, secret string, expiry time.Duration) (string, error) {
	now := time.Now()
	claims.RegisteredClaims = jwt.RegisteredClaims{
		IssuedAt:  jwt.NewNumericDate(now),
		ExpiresAt: jwt.NewNumericDate(now.Add(expiry)),
	}

	token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
	tokenString, err := 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key