roganjoshua
The problem I am trying to solve is this:
There is no authenticated or session user per se, just the browser.
When someone lands on the page I ask them to select a train station as their home train station. I want to store this somewhere, cookie?, so that when they return, that station will be their home station, until they change it.
It isn’t really a session thing, since their is no authentication, I am trying to make it as effortless for the user as possible.
Or is it better to just store it in session anyway?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
BartOtten
Sessions: are gone when the browser is closed
Cookie: Great for permanent data like a location. However, you can’t access cookies from the socket.
The solution when using LiveView? Read the cookie in a conn plug, set it in the session and pick it up in the LiveView again.
LiveView access to cookies
Local storage: this is not send to the server but you might be able to preselect the right location with a Javascript hook. This saves you the hassle of a cookie read, session set and session get.
roganjoshua
Hi Bart
Thanks for the response but I don’t think I need to use liveview on the landing page right?
So when the user hits the site for the first time, I ask for permission to location, then I find the nearest station, I suggest that station might be their home station and if it is or they choose one I set the cookie accordingly.
None of that needs to be liveview but ordinary Phoenix?
Once I have the cookie I can start using Liveview ?
BartOtten
Not sure I understand. LiveView is never a mandatory technique, but when used is might brings benefits over ‘dead views’ in scenario’s with a certain ration of interaction.
Assuming the server is the one finding the nearest location and you don’t mind an old-school full page ‘refresh’ after submitting the location to the server, dead views can do just fine (and simple with cookie). You have a hidden formfield, put the detected location in, submit the form and just handle the form as we have done for decades.
Once you want to use LiveViews in combination with the location, you need to somehow transfer the data in the cookie to the live view process (which can be on an different machine). So usually this is done by reading it in a dead view, setting it in the session and read the session once the live view is mounted.
garrison
Session has two meanings here:
First, there is the
Plug.Sessionwhich is a k/v store (often called a Session in webdev) which stores data either in a cookie on the client (Plug.Session.COOKIE) or in an:etstable (Plug.Session.ETS).Then, there is what is termed a “session cookie”, which is a cookie with no expiry set. When you set a cookie with no expiry (or max-age), the browser will delete that cookie “when it feels like it”, which is usually when the window or browser is closed (but not always).
If you use
Plug.Sessionout of the box, you are probably using thePlug.Session.COOKIEstore with the default settings. The defaultmax-agefor thePlug.Sessioncookie (which is configurable) isnil, meaning the cookie will have no expiry. This leads to the following unfortunate statement:The “Session Cookie” is stored in a “session cookie”.
But it does not have to be a “session cookie” in which you store your “Session Cookie”, because you can set the
:max_ageoption forPlug.Session, and then your Session will survive the browser being closedBut yeah, in practice you can just set a cookie and then load it into the session instead of doing that. That’s what
phx.gen.authdoes.garrison
BTW, to actually answer the OP:
It is fine to store your flag in a cookie.
If you decide you want to use LiveView, you won’t be able to access the cookie directly, but you can copy it from the cookie to the session and then to the assigns. If you want to see an example of this, run
phx.gen.authon an empty project and have a look atuser_auth.ex, particularlyensure_user_token/1andon_mount/4.