gofiber / fiber

⚑️ Express inspired web framework written in Go

Home Page:https://gofiber.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ“ [Feature] [v2]: Add a function to get the session expiry

amirrezaDev1378 opened this issue Β· comments

Feature Proposal Description

Currently, there is no clean and performant way to get session expiry, since there is a SetExpiry function it makes sense to have a function that returns the session expiry.

It can be done using something like this :

// middleware/session/session.go

// GetExpiry gets the expiration of this session
func (s *Session) GetExpiry() time.Duration {
	return s.exp
}

,

Alignment with Express API

This is something similar to :

req.session.cookie.expires  

HTTP RFC Standards Compliance

Confirmed.

API Stability

Hence we are only returning the exp variable which is already declared this feature will not have any stability issue.

Feature Examples

store, err := Seesion.Get(c)
	if err != nil {
		return err
	}
	exp := store.GetExpiry()

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have searched for existing issues that describe my proposal before opening this one.
  • I understand that a proposal that does not meet these guidelines may be closed without explanation.

Thanks for opening your first issue here! πŸŽ‰ Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@amirrezaDev1378, we are planning a rewrite of the session for v3. No changes will be made to v2 as it is in maintenance-only mode at this point.

@sixcolors Oh, I didn't know that....
I will close the issue.

@sixcolors Should we keep this open and move it to v3?

@sixcolors Should we keep this open and move it to v3?

Ref #2741, my plan is to replace the expires mechanism with an idle timeout approach, as it aligns better with the actual behavior of middleware. The plan for a hard expiry is to leave this as an implementation detail for the user which could be accomplished via a key from the session store. However, it would still be a good idea to allow for access to the idle timeout, probably without extending the session.