Monorepo for Tangled tangled.org

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
··· 127 127 return s.Status 128 128 } 129 129 130 + func (a *Auth) ClearSession(r *http.Request, w http.ResponseWriter) error { 131 + clientSession, _ := a.Store.Get(r, appview.SessionName) 132 + clientSession.Options.MaxAge = -1 133 + return clientSession.Save(r, w) 134 + } 135 + 130 136 func (a *Auth) StoreSession(r *http.Request, w http.ResponseWriter, atSessionish Sessionish, pdsEndpoint string) error { 131 137 clientSession, _ := a.Store.Get(r, appview.SessionName) 132 138 clientSession.Values[appview.SessionHandle] = atSessionish.GetHandle()
+4 -1
appview/pages/templates/layouts/topbar.html
··· 1 1 {{ define "layouts/topbar" }} 2 2 {{ with .LoggedInUser }} 3 - <nav class="flex items-center justify-center space-x-4 mb-4 py-2 border-b border-l border-r border-black"> 3 + <nav 4 + class="flex items-center justify-center space-x-4 mb-4 py-2 border-b border-l border-r border-black" 5 + > 4 6 <a 5 7 href="/" 6 8 hx-boost="true" ··· 40 42 >my profile</a 41 43 > 42 44 {{ end }} 45 + <button hx-get="/logout" class="btn">logout</a> 43 46 </nav> 44 47 {{ else }} 45 48 <a href="/login" class="btn my-2 no-underline">login</a>
+7
appview/state/state.go
··· 150 150 } 151 151 } 152 152 153 + func (s *State) Logout(w http.ResponseWriter, r *http.Request) { 154 + s.auth.ClearSession(r, w) 155 + s.pages.HxRedirect(w, "/") 156 + } 157 + 153 158 func (s *State) Timeline(w http.ResponseWriter, r *http.Request) { 154 159 user := s.auth.GetUser(r) 155 160 s.pages.Timeline(w, pages.TimelineParams{ ··· 728 733 r.Handle("/static/*", s.pages.Static()) 729 734 730 735 r.Get("/", s.Timeline) 736 + 737 + r.Get("/logout", s.Logout) 731 738 732 739 r.Get("/login", s.Login) 733 740 r.Post("/login", s.Login)