-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Working on Phoenix Liveview #115
Comments
First of all, sorry about the delay in getting back to you - I haven't felt well recently. About the |
Just FYI, I had no problem making Phauxth work with LiveView using the following "helper" module: defmodule PlaygroundWeb.Auth.Live do
@moduledoc """
Provides authenticated user to live views.
## Usage
defmodule PlaygroundWeb.HomeLive do
use PlaygroundWeb, :live
import PlaygroundWeb.Auth.Live
def mount(_params, session, socket) do
socket = put_current_user(socket, session)
# ...
end
"""
def get_current_user(session) do
with {:ok, session_id} <- Map.fetch(session, "phauxth_session_id"),
user = %{} <- Playground.Accounts.get_by(%{"session_id" => session_id}) do
user
else
_ -> nil
end
end
def put_current_user(socket, session) do
Phoenix.LiveView.assign(socket, current_user: get_current_user(session))
end
end My concern here in context of long-lived live view sessions is that this solution is affected by session expiration after the @riverrun From your perspective, how this should be approached both in context of regular HTTP requests and long-lived live views? I saw #38 for API tokens so I'm wondering if the solution would be similar for sessions e.g. to add HTTP plug after |
I think more and more clear is many apps moving to LiveView direction, LiveView support is mandatory now. Please implement. Also Phx 1.5 out. thanks!!! |
A simpler solution that I would just try is redirect the user to the login page post expiry notice from the authenticate function. If your application requires long lived sessions, then the right way is probably to increase the expiry of the session itself. That's how I would do it anyway, just my $0.02. Hence, I think if we just use your helper and have authenticate redirect to login post expiry would close this issue IMO. |
Problem
Tried to use on Liveview websocket, but not working
Solution
Need to work on Liveview
Additional info
Looks like not able to compile:
defmodule HelloWeb.UserLive.Index do
use Phoenix.LiveView
lib/hello_web/live/user_live/index.ex:11: undefined function plug/1
The text was updated successfully, but these errors were encountered: