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

feature request: add a declarative "hook" to populate new sessions with data #20

Open
mingfang opened this issue Oct 16, 2015 · 3 comments

Comments

@mingfang
Copy link

Use case: When a session is create I would like to load session data from storage such as mysql. This data may include user profile data such as first and last name.

Currently I can do this using Lua at the time when a session is created. However I want to treat session creation as "non-functional" and generic, while still giving each application an ability to populate the session with "functional" information.

One thought I have is to configure an internal location block, e.g. set $session.loader _my_session_loader;, and then at some point in the session lifecycle, we can make a subrequest to the loader. The result of the loader will be stored in the session.

Thoughts?

@bungle
Copy link
Owner

bungle commented Oct 16, 2015

Hi, I kinda understand what you want.

  1. When session is started and it is a new one, you want to execute a function (callback/event handler) to retrieve some user's data that does something like this:
session.data = load_user_data_table(userid)

One way to do it currently is that you create your own wrapper (or proxy), and not use session directly. It isn't hard to add this to session but how would you signal your session.loader to load particular users' data (see above the userid argument)?

Maybe others need this as well. Can you maybe fork this project and then show me how you would like this to work, there is not too many lines in session.lua.

@mingfang
Copy link
Author

mingfang commented Dec 9, 2015

I ended doing something low tech here
https://github.com/mingfang/docker-knginx/blob/master/saml/saml.lua#L65

Thanks again for giving us Resty Session!
Please feel free to close this issue.

@bungle
Copy link
Owner

bungle commented Dec 10, 2015

I think we could add somekind of callbacks to session that are called if they are defined on different phases of session creation, destruction etc.

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

No branches or pull requests

2 participants