Session not saving in Elixir Phoenix
I'm making a signin controller.
I set the session as such:
conn = put_session(conn, :user_id, user.id)
IEx.pry
redirect conn, to: account_path(conn, :show)
It looks set as on the pry line when I print the conn I get
...
:plug_session => %{"user_id" => 6}, :plug_session_fetch => :done,
...
Then in the next controller which we redirect to we get
get_session(conn, :user_id) => nil
The 302 from the signin controller seems to set a session cookie as the response includes
set-cookie:_rebirth_key=g3QAAAABbQAAAAd1c2VyX2lkYQY=--KJ9iow5QUIqw1ggyPla--EGp-dY=; path=/; HttpOnly
How do I make the session persist?
Thanks!
elixir phoenix-framework
add a comment |
I'm making a signin controller.
I set the session as such:
conn = put_session(conn, :user_id, user.id)
IEx.pry
redirect conn, to: account_path(conn, :show)
It looks set as on the pry line when I print the conn I get
...
:plug_session => %{"user_id" => 6}, :plug_session_fetch => :done,
...
Then in the next controller which we redirect to we get
get_session(conn, :user_id) => nil
The 302 from the signin controller seems to set a session cookie as the response includes
set-cookie:_rebirth_key=g3QAAAABbQAAAAd1c2VyX2lkYQY=--KJ9iow5QUIqw1ggyPla--EGp-dY=; path=/; HttpOnly
How do I make the session persist?
Thanks!
elixir phoenix-framework
add a comment |
I'm making a signin controller.
I set the session as such:
conn = put_session(conn, :user_id, user.id)
IEx.pry
redirect conn, to: account_path(conn, :show)
It looks set as on the pry line when I print the conn I get
...
:plug_session => %{"user_id" => 6}, :plug_session_fetch => :done,
...
Then in the next controller which we redirect to we get
get_session(conn, :user_id) => nil
The 302 from the signin controller seems to set a session cookie as the response includes
set-cookie:_rebirth_key=g3QAAAABbQAAAAd1c2VyX2lkYQY=--KJ9iow5QUIqw1ggyPla--EGp-dY=; path=/; HttpOnly
How do I make the session persist?
Thanks!
elixir phoenix-framework
I'm making a signin controller.
I set the session as such:
conn = put_session(conn, :user_id, user.id)
IEx.pry
redirect conn, to: account_path(conn, :show)
It looks set as on the pry line when I print the conn I get
...
:plug_session => %{"user_id" => 6}, :plug_session_fetch => :done,
...
Then in the next controller which we redirect to we get
get_session(conn, :user_id) => nil
The 302 from the signin controller seems to set a session cookie as the response includes
set-cookie:_rebirth_key=g3QAAAABbQAAAAd1c2VyX2lkYQY=--KJ9iow5QUIqw1ggyPla--EGp-dY=; path=/; HttpOnly
How do I make the session persist?
Thanks!
elixir phoenix-framework
elixir phoenix-framework
edited Mar 23 '16 at 16:41
Joel Jackson
asked Mar 22 '16 at 16:40
Joel JacksonJoel Jackson
550419
550419
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I am not sure but I think fetch_session
might not be the right function to get the value from the session. Try
get_session(conn, :user_id)
instead.
To elaborate.put_session
adds a specified value for a key,get_session
will return that value by its key. Source: get_session docs.fetch_session
fetches session from the session store or cookie.
– dannypaz
Mar 22 '16 at 23:38
My bad, I used get_session, weird typo. Edited.
– Joel Jackson
Mar 23 '16 at 16:41
add a comment |
To people who might run into the same problem I did; make sure you're not calling configure_session(drop: true)
unless you really want to.
If, in an attempt to enforce a fresh session (like if a user just logged in) and you call conn |> configure_session(drop: true) |> clear_session |> put_session(:key, value)
, your session will be empty.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36160234%2fsession-not-saving-in-elixir-phoenix%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I am not sure but I think fetch_session
might not be the right function to get the value from the session. Try
get_session(conn, :user_id)
instead.
To elaborate.put_session
adds a specified value for a key,get_session
will return that value by its key. Source: get_session docs.fetch_session
fetches session from the session store or cookie.
– dannypaz
Mar 22 '16 at 23:38
My bad, I used get_session, weird typo. Edited.
– Joel Jackson
Mar 23 '16 at 16:41
add a comment |
I am not sure but I think fetch_session
might not be the right function to get the value from the session. Try
get_session(conn, :user_id)
instead.
To elaborate.put_session
adds a specified value for a key,get_session
will return that value by its key. Source: get_session docs.fetch_session
fetches session from the session store or cookie.
– dannypaz
Mar 22 '16 at 23:38
My bad, I used get_session, weird typo. Edited.
– Joel Jackson
Mar 23 '16 at 16:41
add a comment |
I am not sure but I think fetch_session
might not be the right function to get the value from the session. Try
get_session(conn, :user_id)
instead.
I am not sure but I think fetch_session
might not be the right function to get the value from the session. Try
get_session(conn, :user_id)
instead.
answered Mar 22 '16 at 17:18
NoDisplayNameNoDisplayName
7,52683777
7,52683777
To elaborate.put_session
adds a specified value for a key,get_session
will return that value by its key. Source: get_session docs.fetch_session
fetches session from the session store or cookie.
– dannypaz
Mar 22 '16 at 23:38
My bad, I used get_session, weird typo. Edited.
– Joel Jackson
Mar 23 '16 at 16:41
add a comment |
To elaborate.put_session
adds a specified value for a key,get_session
will return that value by its key. Source: get_session docs.fetch_session
fetches session from the session store or cookie.
– dannypaz
Mar 22 '16 at 23:38
My bad, I used get_session, weird typo. Edited.
– Joel Jackson
Mar 23 '16 at 16:41
To elaborate.
put_session
adds a specified value for a key, get_session
will return that value by its key. Source: get_session docs. fetch_session
fetches session from the session store or cookie.– dannypaz
Mar 22 '16 at 23:38
To elaborate.
put_session
adds a specified value for a key, get_session
will return that value by its key. Source: get_session docs. fetch_session
fetches session from the session store or cookie.– dannypaz
Mar 22 '16 at 23:38
My bad, I used get_session, weird typo. Edited.
– Joel Jackson
Mar 23 '16 at 16:41
My bad, I used get_session, weird typo. Edited.
– Joel Jackson
Mar 23 '16 at 16:41
add a comment |
To people who might run into the same problem I did; make sure you're not calling configure_session(drop: true)
unless you really want to.
If, in an attempt to enforce a fresh session (like if a user just logged in) and you call conn |> configure_session(drop: true) |> clear_session |> put_session(:key, value)
, your session will be empty.
add a comment |
To people who might run into the same problem I did; make sure you're not calling configure_session(drop: true)
unless you really want to.
If, in an attempt to enforce a fresh session (like if a user just logged in) and you call conn |> configure_session(drop: true) |> clear_session |> put_session(:key, value)
, your session will be empty.
add a comment |
To people who might run into the same problem I did; make sure you're not calling configure_session(drop: true)
unless you really want to.
If, in an attempt to enforce a fresh session (like if a user just logged in) and you call conn |> configure_session(drop: true) |> clear_session |> put_session(:key, value)
, your session will be empty.
To people who might run into the same problem I did; make sure you're not calling configure_session(drop: true)
unless you really want to.
If, in an attempt to enforce a fresh session (like if a user just logged in) and you call conn |> configure_session(drop: true) |> clear_session |> put_session(:key, value)
, your session will be empty.
edited Nov 25 '18 at 13:42
ayaio
58.2k20132187
58.2k20132187
answered Nov 25 '18 at 11:35
purplelulupurplelulu
18415
18415
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36160234%2fsession-not-saving-in-elixir-phoenix%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown