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

Does Regenerate method from session save data associated with the old id session with new one ? #2606

Closed
3 tasks done
ADTMike opened this issue Aug 28, 2023 · 6 comments
Closed
3 tasks done

Comments

@ADTMike
Copy link

ADTMike commented Aug 28, 2023

Question Description

Tested threw middleware wrapper in the same ctx meaning the wrapper handler it's keep data associated with the session id and when reaching endpoint (controller) got nil on Get(key) does Regenerate also defer with Save() ?

Code Snippet (optional)

No response

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.
@welcome
Copy link

welcome bot commented Aug 28, 2023

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

@ReneWerner87
Copy link
Member

func (s *Session) Regenerate() error {
// Delete old id from storage
if err := s.config.Storage.Delete(s.id); err != nil {
return err
}
// Generate a new session, and set session.fresh to true
s.refresh()
return nil
}
// refresh generates a new session, and set session.fresh to be true
func (s *Session) refresh() {
// Create a new id
s.id = s.config.KeyGenerator()
// We assign a new id to the session, so the session must be fresh
s.fresh = true
}

with the new id

@ReneWerner87
Copy link
Member

regenerate triggers the old data in the storage to be deleted and the id to be regenerated
if you want to save the current data afterwards, you have to execute save again

@ADTMike
Copy link
Author

ADTMike commented Aug 28, 2023

Ok, thank you for your brief response please can you keep this thread open because i m gonna make some well structured testes, shortly in my wrapper i used Regenerate and Save and without tranferring data manually i can not be able to get them back from controller

@ReneWerner87
Copy link
Member

@ADTMike can i close the report ?

@ADTMike
Copy link
Author

ADTMike commented Sep 1, 2023

Sorry don't have much time, yes i will open n issue

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

No branches or pull requests

2 participants