admin only route is working

This commit is contained in:
2023-03-29 19:52:46 +11:00
parent 1654ff87ed
commit cc4a890064
7 changed files with 127 additions and 10 deletions

14
main.go
View File

@@ -25,7 +25,7 @@ func main() {
router := gin.Default()
router.GET("/", func(c *gin.Context) {
time.Sleep(10 * time.Second)
//time.Sleep(10 * time.Second)
c.String(http.StatusOK, "Welcome Gin Server")
})
@@ -36,18 +36,18 @@ func main() {
// Register our routes
public := router.Group("/api")
public.POST("/register", controllers.Register)
public.POST("/login", controllers.Login)
// This is just PoC really, we can get rid of it
//protected := r.Group("/api/admin")
//protected.Use(middlewares.JwtAuthMiddleware())
//protected.GET("/user", controllers.CurrentUser)
// TODO - this should be an authenticated route
adminOnly := router.Group("/api/admin")
adminOnly.Use(middlewares.JwtAuthAdminMiddleware())
adminOnly.POST("/register", controllers.Register)
// Get secrets
protected := router.Group("/api/secret")
protected.Use(middlewares.JwtAuthMiddleware())
protected.GET("/device", controllers.CurrentUser)
protected.GET("/retrieve", controllers.Retrieve)
protected.POST("/store", controllers.Store)
// Initializing the server in a goroutine so that
// it won't block the graceful shutdown handling below