kuon

kuon

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?

Showing Posts 1 to 10

josevalim

josevalim

Creator of Elixir

See the original text I was replying to. :slight_smile: 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:

 live "/foo", FooLiveView, session: [:user_id]

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

kuon OP

Right, I get it, this is what I thought at first, but I wasn’t sure.

daveboo

daveboo

So, I can still build my registration page with liveview, but when signing in, I should just use a normal Phoenix page?

alvises

alvises

Yes. If I understood correctly, LiveView can’t update the :user_id in the session and the LV session is distinct in each browser’s tab.

And two tabs in the same browser won’t sync with each other. Each LiveView session is distinct.

daveboo

daveboo

Must have been a late night back in May…sorry I didn’t thank you, but this was very helpful, thanks!

why

why

Would I be mistaken in thinking that the latest version of LiveView (0.5.0-dev) solves this problem?

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

0.5.0-dev makes the session available but you still can’t edit it.

why

why

Got it, thanks.

tfwright

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

mindok

@tfwright - did you figure this out?

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
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
spammy
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
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
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
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews