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