wmnnd

wmnnd

PhoenixLiveSession: Plug sessions with LiveView integration + PubSub support

Hey folks,

I’ve just published a little library called PhoenixLiveSession.

What is it?

PhoenixLiveSession is a drop-in replacement for the default Plug.Session stores, comes with LiveView integration and Phoenix.PubSub support.

Why did I create it?

My motivation for this was a client project in which I wanted to implement a shopping cart using LiveView.
I wanted to store the shopping cart data in the user session, but so far, doing this with LiveView required some hacky JavaScript trickery and required additional endpoints.

What does it do?

With PhoenixLiveSession you can use put_session/3 on your LiveView sockets and receive session updates via Phoenix.PubSub.

Where can I find it?

You can find the library on Hex:

Contributions on GitHub are welcome:
https://github.com/pentacent/phoenix_live_session

Also check out the blog article I’ve written about the library with code examples and further insights:

I’m curious to hear what you think!

Most Liked

wmnnd

wmnnd

Here’s another small update to Phoenix LiveSession, version 0.1.3.
It fixes an exception caused in some setups in which the session had not been properly initialized prior to calling maybe_subscribe/1.

You can get it now on Hex:

crockwave

crockwave

Brilliant solution

This library adds value to the new LiveView uploads feature, because it provides easy to understand support for allowing LiveView uploads based features such as changing a user avatar or maintaining a shopping cart, to be able to

  • Directly mutate the session
  • Be immediately available to all other LiveViews via PubSub messaging
  • Provide a mutated session immediately available for a LiveView mount event

I think that this solution should be standardized into Phoenix LiveView

rio517

rio517

This is pretty neat. I was just dealing with some issues close to this and wishing I could set something into the session from my LiveView.

My use case is a bit different than yours. and would love to get your perspective. Disclaimer: I’m only a 4 weeks into my first phoenix app.

I have a “current project” selector that I’m pushing into the session, similar to how one might handle a current_user. My selector is loaded in a live_component menu of every page, thus any mounted liveview might trigger the session insertion. It seems like live_components wouldn’t quite be supported by your library, without explicitly passing the session to them somehow. Did I read that right? I also wonder if I could use PhoenixLiveSession.put_session as a stand-alone and redirect to a new liveview rather than subscribing to PubSub.

An easy way to handle those usecases would be nice, but sounds like that is out of the scope of what you want to do with this?

Last Post!

wmnnd

wmnnd

Thanks, I’m glad you’re finding it useful :slight_smile:

Where Next?

Popular in Announcing Top

zorbash
I created Kitto a framework for dashboards inspired by Dashing. The distributed characteristics of Elixir and the low memory footprint...
New
alisinabh
Hey everyone i’ve developed a library for Jalaali calendar for elixir which supports converting Gregorian dates to Jalaali and vice vers...
New
Crowdhailer
Experimenting with this code. OK.try do user <- fetch_user(1) cart <- fetch_cart(1) order = checkout(cart, user) save_orde...
New
kelvinst
Hey everyone! Well, we made this lib a while ago and now we decided to finally go out and public with it! It’s a tool for creating and m...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44532 311
New
kip
Image is an image processing library for Elixir. It is based upon the fabulous vix library that provides a libvips wrapper for Elixir. I...
622 19460 194
New
scohen
Lexical Lexical is a next-generation language server for the Elixir programming language. Features Context aware code completion As-you...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42533 114
New

We're in Beta

About us Mission Statement