Dynamic navbar menu item for sign in, sign out

I would like to add an item to my navbar that changes based on whether the user is signed in or signed out. This is a very common feature–this website has it in the upper right. Currently the best I can do is add static Sign In and Sign Out items to the navbar.

For example, I might provide a JavaScript function whose return value determines the menu item.

Please note that I already have authentication working. Here I am just asking how to improve on my static Sign In and Sign Out items to the Hugo navbar.

As you correctly point out, this is a Javascript question. This is not a Hugo question. Hugo has no idea whether your user is signed in or not at the time the site is generated.

If by “this website” you mean the discourse forum, it is not built with Hugo. The main Hugo website with the docs and themes is made with Hugo. It does not have sign in/out buttons.

Your question is off-topic in this forum because Javascript is a broad topic not specific to Hugo.