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
+17 -3
View File
@@ -67,10 +67,24 @@ func AddLanguageSelectScript(metadata PageWebsiteMetaData) Node {
}
func GetNav(c HtmxContext, metadata PageWebsiteMetaData) Node {
// Create navigation items from metadata
navItems := Map(metadata.NavItems, func(path ActivePath) Node {
return CreateNavItem(c, path)
})
// Check if user is authenticated and add logout button if so
isAuthenticated, authCtx := c.GetAuthContext()
if isAuthenticated {
logoutButton := A(
Href("/logout"),
Text("Logout ("+authCtx.Email+")"),
Class("logout-button"),
)
navItems = append(navItems, logoutButton)
}
return Nav(Class("nav"), Aria("label", "Main Menu"),
Map(metadata.NavItems, func(path ActivePath) Node {
return CreateNavItem(c, path)
}),
Group(navItems),
)
}