forked from tangled.org/core
this repo has no description

appview: basic logout functionality

This should be in the profile dropdown.

anirudh.fi 55c7be27 c843ceea

verified
Changed files
+17 -1
appview
auth
pages
templates
layouts
state
+6
appview/auth/auth.go
···
return s.Status
}
+
func (a *Auth) ClearSession(r *http.Request, w http.ResponseWriter) error {
+
clientSession, _ := a.Store.Get(r, appview.SessionName)
+
clientSession.Options.MaxAge = -1
+
return clientSession.Save(r, w)
+
}
+
func (a *Auth) StoreSession(r *http.Request, w http.ResponseWriter, atSessionish Sessionish, pdsEndpoint string) error {
clientSession, _ := a.Store.Get(r, appview.SessionName)
clientSession.Values[appview.SessionHandle] = atSessionish.GetHandle()
+4 -1
appview/pages/templates/layouts/topbar.html
···
{{ define "layouts/topbar" }}
{{ with .LoggedInUser }}
-
<nav class="flex items-center justify-center space-x-4 mb-4 py-2 border-b border-l border-r border-black">
+
<nav
+
class="flex items-center justify-center space-x-4 mb-4 py-2 border-b border-l border-r border-black"
+
>
<a
href="/"
hx-boost="true"
···
>my profile</a
>
{{ end }}
+
<button hx-get="/logout" class="btn">logout</a>
</nav>
{{ else }}
<a href="/login" class="btn my-2 no-underline">login</a>
+7
appview/state/state.go
···
}
}
+
func (s *State) Logout(w http.ResponseWriter, r *http.Request) {
+
s.auth.ClearSession(r, w)
+
s.pages.HxRedirect(w, "/")
+
}
+
func (s *State) Timeline(w http.ResponseWriter, r *http.Request) {
user := s.auth.GetUser(r)
s.pages.Timeline(w, pages.TimelineParams{
···
r.Handle("/static/*", s.pages.Static())
r.Get("/", s.Timeline)
+
+
r.Get("/logout", s.Logout)
r.Get("/login", s.Login)
r.Post("/login", s.Login)