Handle session termination display and logout redirection
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user