Kill Sessions

This commit is contained in:
2024-01-30 18:18:25 +08:00
parent 2a32c8b2f6
commit e87da59026
4 changed files with 53 additions and 6 deletions

View File

@ -55,6 +55,20 @@ func getEvents(c *fiber.Ctx) error {
})
}
func killSession(c *fiber.Ctx) error {
user := c.Locals("principal").(models.Account)
id, _ := c.ParamsInt("sessionId", 0)
if err := database.C.Delete(&models.AuthSession{}, &models.AuthSession{
BaseModel: models.BaseModel{ID: uint(id)},
AccountID: user.ID,
}).Error; err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
}
return c.SendStatus(fiber.StatusOK)
}
func doRegister(c *fiber.Ctx) error {
var data struct {
Name string `json:"name"`

View File

@ -26,6 +26,7 @@ func NewServer() {
{
api.Get("/users/me", auth, getPrincipal)
api.Get("/users/me/events", auth, getEvents)
api.Delete("/users/me/sessions/:sessionId", auth, killSession)
api.Post("/users", doRegister)
api.Post("/users/me/confirm", doRegisterConfirm)