@@ 73,9 73,7 @@ func setupFrontendRouter() *gin.Engine {
auth := r.Group("/auth")
{
- auth.POST("/login", func(c *gin.Context) {
- handlers.AuthLogin(sessionManager, c)
- })
+ auth.POST("/login", handlers.AuthLogin(sessionManager))
}
// routes for the actual application frontend
@@ 20,22 20,24 @@ type postLoginDetails struct {
Password string `form:"password"`
}
-func AuthLogin(sm *scs.SessionManager, c *gin.Context) {
- data := &postLoginDetails{}
- if err := c.Bind(data); err != nil {
- log.Printf("[felu] ERROR: Could not bind login details: %v", err)
- c.String(http.StatusBadRequest, "Could not bind login details")
- return
- }
+func AuthLogin(sm *scs.SessionManager) gin.HandlerFunc {
+ return func(c *gin.Context) {
+ data := &postLoginDetails{}
+ if err := c.Bind(data); err != nil {
+ log.Printf("[felu] ERROR: Could not bind login details: %v", err)
+ c.String(http.StatusBadRequest, "Could not bind login details")
+ return
+ }
- user, err := db.FetchUserWithCreds(data.Email, data.Password)
- if err != nil {
- c.String(http.StatusUnauthorized, err.Error())
- return
- }
+ user, err := db.FetchUserWithCreds(data.Email, data.Password)
+ if err != nil {
+ c.String(http.StatusUnauthorized, err.Error())
+ return
+ }
- sm.Put(c.Request.Context(), "user_id", user.Id)
+ sm.Put(c.Request.Context(), "user_id", user.Id)
- c.Header("HX-Redirect", "/manage")
- //c.Redirect(http.StatusFound, "/manage")
+ c.Header("HX-Redirect", "/manage")
+ //c.Redirect(http.StatusFound, "/manage")
+ }
}