Add a logout button

This commit is contained in:
Achim Rohn
2025-09-17 18:41:23 +02:00
parent 6e549e2530
commit c4f4c5d637
3 changed files with 33 additions and 9 deletions
+16
View File
@@ -13,6 +13,13 @@ import (
htmx "maragu.dev/gomponents-htmx"
)
const AuthContextKey = "authContext"
type AuthContext struct {
Email string
UserId int
}
type HtmxContext interface {
Render(node gomponents.Node)
SetError(err error)
@@ -29,6 +36,7 @@ type HtmxContext interface {
SetAllRoutes(routes []HtmxRoute)
GetAllRoutes() []HtmxRoute
GetQueryParams() []HtmxPathParam
GetAuthContext() (bool, AuthContext)
}
type HtmxContextImpl struct {
@@ -40,6 +48,14 @@ type HtmxContextImpl struct {
routes []HtmxRoute
}
func (c *HtmxContextImpl) GetAuthContext() (bool, AuthContext) {
authCtx := c.req.Context().Value(AuthContextKey)
if authCtx == nil {
return false, AuthContext{}
}
return true, authCtx.(AuthContext)
}
func (c *HtmxContextImpl) GetQueryParams() []HtmxPathParam {
// Extract query parameters from the current request URL and return them as
// a deterministic list of HtmxPathParam. If a key has multiple values,