Add a logout button
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user