auth

package
v0.1.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2025 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware() gin.HandlerFunc

Middleware verifies JWT tokens and adds user info to the context Can be applied to specific routes that require authentication

func OptionalAuth

func OptionalAuth() gin.HandlerFunc

OptionalAuth middleware that doesn't abort if auth fails Useful for routes that work with different behavior for logged-in vs anonymous users

func RequireAuth

func RequireAuth(group *gin.RouterGroup) *gin.RouterGroup

RequireAuth applies the auth middleware to a specific route group Example usage: RequireAuth(router.Group("/protected"))

func RequireRoleMiddleware

func RequireRoleMiddleware(group *gin.RouterGroup, roleName string) *gin.RouterGroup

RequireRoleMiddleware applies the auth middleware followed by role checking to a specific route group Example usage: RequireRoleMiddleware(router.Group("/admin"), "admin", userRepo)

Types

type UserAuthInfo

type UserAuthInfo struct {
	UserID primitive.ObjectID
	Claims *jwt.CustomClaims
}

UserAuthInfo contains the authenticated user information

func GetAuthUser

func GetAuthUser(c *gin.Context) *UserAuthInfo

GetAuthUser retrieves the authenticated user info from the Gin context Use this in your handlers after applying the AuthMiddleware

Jump to

Keyboard shortcuts

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