appview: basic logout functionality
This should be in the profile dropdown.
Anirudh Oppiliappan 2 weeks ago 3 files (+17, -1)
MODIFIED
appview/auth/auth.go
MODIFIED
appview/auth/auth.go
@@ -127,6 +127,12 @@ func (s *CreateSessionWrapper) GetStatus() *string {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()
@@ -1,6 +1,8 @@{{ 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"+ ><ahref="/"hx-boost="true"@@ -40,6 +42,7 @@ class="text-gray-600 hover:text-gray-900 no-underline">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>
MODIFIED
appview/state/state.go
MODIFIED
appview/state/state.go
@@ -150,6 +150,11 @@ return}}+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{@@ -728,6 +733,8 @@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)