diff --git a/public/css/_tw-input.css b/public/css/_tw-input.css index a9ba781..78b6af3 100644 --- a/public/css/_tw-input.css +++ b/public/css/_tw-input.css @@ -32,7 +32,6 @@ a:not(.no-link), button[hx-get], button[hx-post] { - text-decoration: underline; transition: background-color 150ms ease-in, color 150ms ease-in; } @@ -43,6 +42,15 @@ color: var(--background-color); } + a:not(.no-link), + button[hx-get] { + text-decoration: underline; + } + + button[hx-post] { + border-width: 1px; + } + nav a, button[hx-get], button[hx-post] { @@ -81,8 +89,8 @@ } .lightning { - background-color: var(--lightning-color); - color: var(--black); + background-color: var(--lightning-color) !important; + color: var(--black) !important; } .lightning:hover { @@ -90,8 +98,8 @@ } .nostr { - background-color: var(--nostr-color); - color: var(--white); + background-color: var(--nostr-color) !important; + color: var(--white) !important; } .nostr:hover { diff --git a/server/router/handler/auth.go b/server/router/handler/auth.go index 1f2f033..87ee06d 100644 --- a/server/router/handler/auth.go +++ b/server/router/handler/auth.go @@ -186,3 +186,33 @@ func mapAction(action string) string { return action } } + +func HandleLogout(sc context.Context) echo.HandlerFunc { + return func(c echo.Context) error { + var ( + db = sc.Db + ctx = c.Request().Context() + cookie *http.Cookie + sessionId string + err error + ) + + if cookie, err = c.Cookie("session"); err != nil { + // cookie not found + return c.JSON(http.StatusNotFound, "session not found") + } + + sessionId = cookie.Value + if _, err = db.ExecContext(ctx, + "DELETE FROM sessions WHERE id = $1", sessionId); err != nil { + return err + } + + // tell browser that cookie is expired and thus can be deleted + c.SetCookie(&http.Cookie{Name: "session", HttpOnly: true, Path: "/", Value: sessionId, Secure: true, Expires: time.Now()}) + + return c.Redirect(http.StatusSeeOther, "/") + // c.Response().Header().Set("HX-Location", "/") + // return c.JSON(http.StatusOK, nil) + } +} diff --git a/server/router/handler/user.go b/server/router/handler/user.go new file mode 100644 index 0000000..894f796 --- /dev/null +++ b/server/router/handler/user.go @@ -0,0 +1,15 @@ +package handler + +import ( + "git.ekzyis.com/ekzyis/delphi.market/server/router/context" + "git.ekzyis.com/ekzyis/delphi.market/server/router/pages" + "git.ekzyis.com/ekzyis/delphi.market/types" + "github.com/labstack/echo/v4" +) + +func HandleUser(sc context.Context) echo.HandlerFunc { + return func(c echo.Context) error { + u := c.Get("session").(types.User) + return pages.User(&u).Render(context.RenderContext(sc, c), c.Response().Writer) + } +} diff --git a/server/router/middleware/session.go b/server/router/middleware/session.go index dda2eb4..2bb17d1 100644 --- a/server/router/middleware/session.go +++ b/server/router/middleware/session.go @@ -46,6 +46,7 @@ func SessionGuard(sc context.Context) echo.MiddlewareFunc { return func(c echo.Context) error { session := c.Get("session") if session == nil { + // this seems to work for non-interactive and htmx requests return c.Redirect(http.StatusTemporaryRedirect, "/login") } return next(c) diff --git a/server/router/pages/components/nav.templ b/server/router/pages/components/nav.templ index 78248ff..03388ae 100644 --- a/server/router/pages/components/nav.templ +++ b/server/router/pages/components/nav.templ @@ -4,7 +4,14 @@ import c "git.ekzyis.com/ekzyis/delphi.market/server/router/context" templ Nav() {
-