Please excuse me if the followings are dumb questions. I am entirely new to not only Phoenix and Elixir, but also web development.
1) When put_session/3 is used, are session data stored on server side or client side by default?
The section on "Sessions" of Phoenix's user's guide does not give any explicit answer. It says that the default storage method is "Plug's cookie session storage", while "Phoenix also supports server-side sessions via ETS" but"We don’t recommend using this store in production".
As the term "cookie" is used in the former and the adjective "server-side" is mentioned only in the ETS storage, I'm confused and I wonder if "cookie session storage" means storing session data on a cookie that is sent to the client side.
2) What is the lifetime of a Phoenix connection (I mean the "conn" thing)?
3) When should I put data inside conn.assigns and when should I use put_session/3 ? In chapter 6 of Programming Phoenix (which Chris McCord coauthors) there is an example of user authentication. The authenticated user is stored in conn.assigns.current_user . Is there any good reason not to store this in session data?
1) Cookie session storage means that all the session data is stored in the cookie and encrypted (or at least signed) to prevent tampering. Alternatives are server based sessions, where usually a cookie is set with a session ID and all the data is stored on the server. Cookie based sessions are much easier to scale since you don't have to share data between multiple backend in a load balancer, drive all the data is included in each request via the cookie. Cookies are in practice bounded size wise and require a lot of redundant data transfer and parsing. As stated, prefer cookie sessions unless you really can't use them.
2) Life cycle of a connection is effectively a single request.
3) The general practice is to store things you need across requests in the session, but early in the connections lifecycle you pull the data out and put it in connection assigns. In the case of an authed user, you would store the user ID in the session and immediately use it to retrieve the full user object and store the full user object in Conn assigns. Then, for the rest of the request you can access it in its entirety. So again, store the essentials in session and then use them to populate Conn assigns.
--
You received this message because you are subscribed to the Google Groups "phoenix-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phoenix-talk...@googlegroups.com.
To post to this group, send email to phoeni...@googlegroups.com.
Visit this group at https://groups.google.com/group/phoenix-talk.
To view this discussion on the web visit https://groups.google.com/d/msgid/phoenix-talk/7e34e056-f5ca-4b4e-962f-c4014dc68be5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
1) Cookie session storage means that all the session data is stored in the cookie and encrypted (or at least signed) to prevent tampering. Alternatives are server based sessions, where usually a cookie is set with a session ID and all the data is stored on the server.
--
You received this message because you are subscribed to the Google Groups "phoenix-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phoenix-talk...@googlegroups.com.
To post to this group, send email to phoeni...@googlegroups.com.
Visit this group at https://groups.google.com/group/phoenix-talk.
To view this discussion on the web visit https://groups.google.com/d/msgid/phoenix-talk/5a79c778-fc8b-438a-a15b-fb04494b9749%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "phoenix-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to phoenix-talk...@googlegroups.com.
To post to this group, send email to phoeni...@googlegroups.com.
Visit this group at https://groups.google.com/group/phoenix-talk.
To view this discussion on the web visit https://groups.google.com/d/msgid/phoenix-talk/c76f15ac-9be6-6e2b-f2b6-a5a18bfa7fc4%40wildgooses.com.