Handle session termination display and logout redirection

This commit is contained in:
2024-09-21 19:27:23 +07:00
parent 80941bd3bb
commit 3cc0322aa1
5 changed files with 126 additions and 213 deletions

View File

@ -16,10 +16,14 @@ import (
"github.com/fossyy/filekeeper/utils"
)
var ErrorSessionNotFound = errors.New("session not found")
type Session struct {
ID string
}
type UserStatus string
type SessionInfo struct {
SessionID string
Browser string
@ -30,8 +34,6 @@ type SessionInfo struct {
Location string
}
type UserStatus string
const (
Authorized UserStatus = "authorized"
Unauthorized UserStatus = "unauthorized"
@ -115,6 +117,9 @@ func RemoveSessionInfo(email string, id string) error {
key := "UserSessionInfo:" + email + ":" + id
err := app.Server.Cache.DeleteCache(context.Background(), key)
if err != nil {
if errors.Is(err, redis.Nil) {
return ErrorSessionNotFound
}
return err
}
return nil
@ -150,7 +155,7 @@ func GetSessionInfo(email string, id string) (*SessionInfo, error) {
sessionInfoData, err := app.Server.Cache.GetCache(context.Background(), key)
if err != nil {
if errors.Is(err, redis.Nil) {
return nil, nil
return nil, ErrorSessionNotFound
}
return nil, err
}