Session not saving in Elixir Phoenix












0















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!










share|improve this question





























    0















    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!










    share|improve this question



























      0












      0








      0








      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!










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 23 '16 at 16:41







      Joel Jackson

















      asked Mar 22 '16 at 16:40









      Joel JacksonJoel Jackson

      550419




      550419
























          2 Answers
          2






          active

          oldest

          votes


















          2














          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.






          share|improve this answer
























          • 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



















          0














          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.






          share|improve this answer

























            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
            });


            }
            });














            draft saved

            draft discarded


















            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









            2














            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.






            share|improve this answer
























            • 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
















            2














            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.






            share|improve this answer
























            • 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














            2












            2








            2







            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.






            share|improve this answer













            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.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            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



















            • 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













            0














            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.






            share|improve this answer






























              0














              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.






              share|improve this answer




























                0












                0








                0







                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.






                share|improve this answer















                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.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 25 '18 at 13:42









                ayaio

                58.2k20132187




                58.2k20132187










                answered Nov 25 '18 at 11:35









                purplelulupurplelulu

                18415




                18415






























                    draft saved

                    draft discarded




















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    404 Error Contact Form 7 ajax form submitting

                    How to know if a Active Directory user can login interactively

                    TypeError: fit_transform() missing 1 required positional argument: 'X'