Fix session retrieval issue after migrating to Redis cache
This commit is contained in:
@ -2,6 +2,7 @@ package logoutHandler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/fossyy/filekeeper/types"
|
||||
"net/http"
|
||||
|
||||
"github.com/fossyy/filekeeper/session"
|
||||
@ -9,12 +10,12 @@ import (
|
||||
)
|
||||
|
||||
func GET(w http.ResponseWriter, r *http.Request) {
|
||||
userSession := r.Context().Value("user").(types.User)
|
||||
cookie, err := r.Cookie("Session")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
storeSession, err := session.Get(cookie.Value)
|
||||
storeSession := session.Get(cookie.Value)
|
||||
if err != nil {
|
||||
if errors.Is(err, &session.SessionNotFoundError{}) {
|
||||
storeSession.Destroy(w)
|
||||
@ -23,8 +24,16 @@ func GET(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
storeSession.Delete()
|
||||
session.RemoveSessionInfo(storeSession.Values.Email, cookie.Value)
|
||||
err = storeSession.Delete()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return
|
||||
}
|
||||
err = session.RemoveSessionInfo(userSession.Email, cookie.Value)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return
|
||||
}
|
||||
|
||||
http.SetCookie(w, &http.Cookie{
|
||||
Name: utils.Getenv("SESSION_NAME"),
|
||||
|
Reference in New Issue
Block a user