fix: auth flow fixed, add getOrCreate method for user
This commit is contained in:
@@ -73,7 +73,7 @@ func (h *AuthHandler) Authenticate(c *fiber.Ctx) error {
|
||||
c.Context(),
|
||||
req.PubKey,
|
||||
req.Signature,
|
||||
// add chainID to cfg
|
||||
//TODO: add chainID to cfg
|
||||
1,
|
||||
c.IP(),
|
||||
c.Get("User-Agent"),
|
||||
@@ -90,3 +90,9 @@ func (h *AuthHandler) Authenticate(c *fiber.Ctx) error {
|
||||
ExpiresAt: userToken.ExpiresAt,
|
||||
})
|
||||
}
|
||||
|
||||
func (h *AuthHandler) HelloWorld(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusOK).JSON(fiber.Map{
|
||||
"message": "Hello, World!",
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"backend/config"
|
||||
"backend/docs"
|
||||
httpHandlers "backend/internal/api/http/handlers"
|
||||
"backend/internal/api/http/middlewares"
|
||||
"backend/internal/app"
|
||||
"fmt"
|
||||
"log"
|
||||
@@ -14,19 +15,27 @@ import (
|
||||
)
|
||||
|
||||
func Run(cfg config.Server, app *app.AppContainer) {
|
||||
router := fiber.New()
|
||||
fiberApp := fiber.New()
|
||||
|
||||
api := router.Group("/api")
|
||||
// Serve static files (HTML, CSS, JS)
|
||||
fiberApp.Static("/", "./")
|
||||
|
||||
api := fiberApp.Group("/api")
|
||||
// register routes here
|
||||
registerPublicRoutes(api, app)
|
||||
|
||||
docs.SwaggerInfo.Host = ""
|
||||
docs.SwaggerInfo.Schemes = []string{}
|
||||
docs.SwaggerInfo.Host = fmt.Sprintf("%s:%d", cfg.Host, cfg.Port)
|
||||
docs.SwaggerInfo.BasePath = "/api"
|
||||
docs.SwaggerInfo.Schemes = []string{"http", "https"}
|
||||
|
||||
router.Get("/swagger/*", adaptor.HTTPHandler(httpSwagger.Handler()))
|
||||
api.Get("/swagger/*", adaptor.HTTPHandler(httpSwagger.Handler()))
|
||||
|
||||
log.Fatal(router.Listen(fmt.Sprintf("%s:%d", cfg.Host, cfg.Port)))
|
||||
api.Get("/hello", middlewares.JWTAuthMiddleware([]byte("Secret")), func(c *fiber.Ctx) error {
|
||||
return c.SendString("Hello, World!")
|
||||
})
|
||||
|
||||
log.Printf("Server starting on %s:%d", cfg.Host, cfg.Port)
|
||||
log.Fatal(fiberApp.Listen(fmt.Sprintf("%s:%d", cfg.Host, cfg.Port)))
|
||||
}
|
||||
|
||||
func registerPublicRoutes(router fiber.Router, app *app.AppContainer) {
|
||||
|
||||
Reference in New Issue
Block a user