Skip to content

Commit

Permalink
Simplify sign out handler
Browse files Browse the repository at this point in the history
  • Loading branch information
theandrew168 committed Sep 1, 2024
1 parent a301b84 commit e05e85f
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions backend/web/page/signout.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ func HandleSignoutForm(store *storage.Storage) http.Handler {
return
}

// Delete the existing session cookie.
cookie := util.NewExpiredCookie(util.SessionCookieName)
http.SetCookie(w, &cookie)

// Lookup the session by it's client-side session ID.
session, err := store.Session().ReadBySessionID(sessionID.Value)
if err != nil {
switch {
case errors.Is(err, postgres.ErrNotFound):
// Delete the existing session cookie.
cookie := util.NewExpiredCookie(util.SessionCookieName)
http.SetCookie(w, &cookie)
http.Redirect(w, r, "/", http.StatusSeeOther)
default:
http.Error(w, err.Error(), 500)
Expand All @@ -37,20 +38,13 @@ func HandleSignoutForm(store *storage.Storage) http.Handler {
if err != nil {
switch {
case errors.Is(err, postgres.ErrNotFound):
// Delete the existing session cookie.
cookie := util.NewExpiredCookie(util.SessionCookieName)
http.SetCookie(w, &cookie)
http.Redirect(w, r, "/", http.StatusSeeOther)
default:
http.Error(w, err.Error(), 500)
}
return
}

// Delete the existing session cookie.
cookie := util.NewExpiredCookie(util.SessionCookieName)
http.SetCookie(w, &cookie)

// Redirect back to the index page.
http.Redirect(w, r, "/", http.StatusSeeOther)
})
Expand Down

0 comments on commit e05e85f

Please sign in to comment.