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