kuon
How to manage session state with live view
When reading about live view, I read this from José:
Why would the login be an horrible idea for LiveView?
And, as a more general question, how should session be managed when using LiveView. For regular app, and API endpoints, I usually just have a require_user plug that check the session for a user_id and retrieve the corresponding user from the database. My login action just |> put_session("user_id", user.id) after a successful login.
How would this work with LiveView?
Trending in Questions
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated!
To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead.
Sta...
New
Hello !
We want new/edit form pages to POST/PUT to their own URL rather than the resources REST defaults (post /things, put /things/:id)...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New
Other Trending Topics
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #performance
- #security










First 10 of 22 Posts
josevalim
See the original text I was replying to.
If you login through LiveView, then if you navigate to another page or open up another tab, you will have to login again. LiveView keeps the current page state.
When you render a liveview, one of the parameters is the session, which are the session fields currently in your session that you want to send to the liveview.
So if you do:
Then the user_id field will also be available in the LiveView mount, which you can retrieve it from the database once again.
So the idea is to login as usual and then pass the relevant session fields to the live view.
kuon
Right, I get it, this is what I thought at first, but I wasn’t sure.
daveboo
So, I can still build my registration page with liveview, but when signing in, I should just use a normal Phoenix page?
alvises
Yes. If I understood correctly, LiveView can’t update the
:user_idin the session and the LV session is distinct in each browser’s tab.daveboo
Must have been a late night back in May…sorry I didn’t thank you, but this was very helpful, thanks!
why
Would I be mistaken in thinking that the latest version of LiveView (0.5.0-dev) solves this problem?
benwilson512
0.5.0-dev makes the session available but you still can’t edit it.
why
Got it, thanks.
tfwright
If I were set on storing some data about a LV session in the browser session, what would be the best way to do that? Add a vanilla JS link that points to a non-LV controller?
My use-case is that I would like to save some UI state for a returning user even if they don’t login (or have an account).
mindok
@tfwright - did you figure this out?