jwt

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JWT

type JWT struct {
	CookieName string        // Name of the cookie to store the JWT
	Secret     string        // Secret key used to sign the JWT
	TokenTTL   time.Duration // Token time-to-live duration
}

JWT handles JWT token creation, validation, and cookie management.

func NewJWT

func NewJWT(jwtCfg *cfg.JWTConfig) *JWT

func (*JWT) GenerateToken

func (j *JWT) GenerateToken(email string) (string, error)

GenerateToken creates a signed JWT token containing the user's email and expiration.

func (*JWT) SetCookie

func (j *JWT) SetCookie(w http.ResponseWriter, token string)

SetCookie sets an HTTP-only, secure cookie with the JWT token on the response writer.

func (*JWT) ValidateJWT

func (j *JWT) ValidateJWT(tokenString string) (string, error)

ValidateJWT parses and validates the JWT token string. Returns the email claim if valid, or an error otherwise.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL