Fix session retrieval issue after migrating to Redis cache

This commit is contained in:
2024-09-08 16:41:33 +07:00
parent 2c5de2b336
commit 29ab28fd93
5 changed files with 30 additions and 42 deletions

View File

@ -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"),