Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: add Delete method to Store struct in session middleware #2655

Merged
merged 2 commits into from
Oct 2, 2023

Conversation

kaptinlin
Copy link
Contributor

@kaptinlin kaptinlin commented Sep 30, 2023

Description

This pull request introduces a new Delete method to the Store struct in the Fiber's session middleware. The Delete method is designed to delete a specific session id from the storage.

The motivation behind this change is to provide more control over individual session management, especially in scenarios like administrator-enforced user logout or user-initiated logout from a specific device session. With the Delete method, we can easily delete a specific session, providing a more efficient and flexible way to manage individual user sessions.

This pull request also includes relevant test code to ensure the correct functionality of the Delete method.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Checklist:

  • For new functionalities I follow the inspiration of the express js framework and built them similar in usage
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation - /docs/ directory for https://docs.gofiber.io/
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • If new dependencies exist, I have checked that they are really necessary and agreed with the maintainers/community (we want to have as few dependencies as possible)
  • I tried to make my code as fast as possible with as few allocations as possible
  • For new code I have written benchmarks so that they can be analyzed and improved

Usage

app.Post("/admin/session/:id/logout", func(c *fiber.Ctx) error {
    // Get session id from request
    sessionID := c.Params("id")

    // Delete the session
    if err := store.Delete(sessionID); err != nil {
        return c.Status(500).SendString(err.Error())
    }

    return c.SendString("Logout successful")
})

middleware/session/store.go Outdated Show resolved Hide resolved
middleware/session/store.go Outdated Show resolved Hide resolved
@ReneWerner87
Copy link
Member

@kaptinlin pls check the review comments

@ReneWerner87 ReneWerner87 merged commit d86c257 into gofiber:master Oct 2, 2023
20 checks passed
@welcome
Copy link

welcome bot commented Oct 2, 2023

Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants