Documentation ¶
Index ¶
Constants ¶
View Source
const BCRYPT_COST = 12
Variables ¶
This section is empty.
Functions ¶
func RequireAuth ¶
func RequireAuth(JWTSecret string) gin.HandlerFunc
Middleware that requires a valid JWT token to be present in the Authorization header, meaning the user has an account to modify the functions they own. You want to add this middleware to a group (router.Group()) of routes that require authentication. JWTSecret is the secret key used to sign the JWT tokens. This middleware will set the "userID" and "username" keys in the gin.Context.
Example: ¶
func ConfigureRoutes(router *gin.Engine, db *gorm.DB, jwtSecret string) { controller := Controller{DB: db, JWTSecret: jwtSecret} group := router.Group("/my-prefix") group.Use(RequireAuth(jwtSecret)) group.POST("/", controller.postFunction) group.GET("/test", controller.testFunction) }
Types ¶
type Controller ¶
Click to show internal directories.
Click to hide internal directories.