github.com/saadullahsaeed/fragmenta-cms@v1.5.4/src/users/actions/logout.go (about)

     1  package useractions
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"github.com/fragmenta/auth"
     7  	"github.com/fragmenta/server"
     8  
     9  	"github.com/fragmenta/fragmenta-cms/src/lib/session"
    10  )
    11  
    12  // HandleLogout clears the current user's session /users/logout
    13  func HandleLogout(w http.ResponseWriter, r *http.Request) error {
    14  
    15  	// Check the authenticity token
    16  	err := session.CheckAuthenticity(w, r)
    17  	if err != nil {
    18  		return err
    19  	}
    20  
    21  	// Clear the current session cookie
    22  	auth.ClearSession(w)
    23  
    24  	// Redirect to home
    25  	return server.Redirect(w, r, "/")
    26  }