session sign out

main
alex 2023-05-18 14:29:56 +02:00
parent ccda8d607e
commit d291a2dd46
3 changed files with 12 additions and 5 deletions

View File

@ -36,5 +36,5 @@ type UserResponse struct {
} }
type UserSignOutSessionRequest struct { type UserSignOutSessionRequest struct {
SessionId string IdForDeletion string
} }

View File

@ -1,8 +1,9 @@
package user package user
import ( import (
"janex/admin-dashboard-backend/modules/database"
"janex/admin-dashboard-backend/modules/structs" "janex/admin-dashboard-backend/modules/structs"
"janex/admin-dashboard-backend/modules/utils" "janex/admin-dashboard-backend/socketclients"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
@ -16,9 +17,15 @@ func SignOutSession(c *fiber.Ctx) error {
return c.SendStatus(fiber.StatusBadRequest) return c.SendStatus(fiber.StatusBadRequest)
} }
log.Debug().Msgf("params %s", params.SessionId) var userSession structs.UserSession
log.Debug().Msgf("userId %s", utils.GetXAuhorizationHeader(c)) database.DB.First(&userSession, "id_for_deletion = ?", params.IdForDeletion)
if userSession.Id != "" {
database.DB.Delete(&structs.UserSession{}, "id = ?", userSession.Id)
socketclients.CloseAllUserSessionConnections(userSession.Id)
}
return c.SendStatus(fiber.StatusOK) return c.SendStatus(fiber.StatusOK)
} }

View File

@ -15,7 +15,7 @@ func SetupRoutes(app *fiber.App) {
u := v1.Group("/user") u := v1.Group("/user")
u.Post("/auth/login", user.UserLogin) u.Post("/auth/login", user.UserLogin)
u.Delete("/auth/logout", user.UserLogout) u.Delete("/auth/logout", user.UserLogout)
u.Delete("/session/:sessionId", user.SignOutSession) u.Delete("/session/:idForDeletion", userSessionValidation, user.SignOutSession)
} }
func userSessionValidation(c *fiber.Ctx) error { func userSessionValidation(c *fiber.Ctx) error {