SpoonWood

SpoonWood

Hello Everyone,

We are using LiveView to build a feature that displays some information in the admin dashboard of our Application, but we are not quite sure how to secure the websocket against access of non registered users.

Is the socket secure if we are using a signing salt and a Session key, having installed LiveView the exact Way thats recommended on Hexdocs.pm (we are using LiveView 0.8.1 currently)

Thank you very much in Advance

Showing Posts 17 to 8

daveboo

daveboo

So, it would be unwise to have live routes behind this pipeline then?

scope “/”, MyAppWeb do
pipe_through [:browser, :visitor, :redirect_if_user_is_authenticated]

live "/user/register", UserNewLive
josevalim

josevalim

Creator of Elixir

Using the route helpers is better because:

  1. you validate the route actually exists in your app.
  2. if you change the url, you don’t have to change the code

That said, this will just work too: <%= link "Logout", to: Routes.user_session_path(@socket, :delete), method: :delete %>.

leductam

leductam

After read the docs about links , I’ve changed the template and now no need to pass @conn:
<li><%= link "Logout", to: "/users/logout", method: :delete %></li>
But I still misunderstand why the default template _user_menu.html.eex in mix phx.gen.auth use @conn at: <%= link "Logout", to: Routes.user_session_path(@conn, :delete), method: :delete %>

Btw, I got the worth information at the commit Add security considerations section to docs.

LostKobrakai

LostKobrakai

You should be able to generate the url just fine with both a conn or a socket. It just can’t be a live_patch or phx-click action, but it must be a proper http call to the server to log the user out.

leductam

leductam

Thank for your instant feedback, but the current logout link in template is:
<%= link "Logout", to: Routes.user_session_path(@conn, :delete), method: :delete %>

Then could we put the @conn to session at the login (as the usual) and use @conn in Liveview (mount(_, session, socket)) to put assigns to render the Logout link?

Imagine that we stand somewhere in Liveview and need the precisely way to perform logout action.

josevalim

josevalim

Creator of Elixir

The logout action should still be a regular controller action since LiveView cannot set cookies/session.

leductam

leductam

I’m using the LiveView and also approach phx.gen.auth.
The web execute login as usual, but how can we logout by using UserAuth.logout_user from LiveView (no @conn)? As there is the logout templates that are rendered underneath LiveView’s template.

josevalim

josevalim

Creator of Elixir

Here are the changes to enable this feature on top mix phx.gen.auth: Set the live_socket_id on login and disconnect on logout · dashbitco/mix_phx_gen_auth_demo@1eebcae · GitHub

It is really straight-forward and it is per session (i.e. it doesn’t disconnect all sessions, only the current one).

josevalim

josevalim

Creator of Elixir

You can also disconnect just one of the sessions. All you have to do is identify the connections per session token rather than user id. That’s what I am submitting to mix phx.gen.auth.

Exadra37

Exadra37

Sorry I missed that the signature of mount/3 is mount(params, session, socket)… I am feeling a bit stupid now :frowning:

Where Next? Top

Trending in Questions Top

RSP87
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
nseaSeb
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
kpanic
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
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
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
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add 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
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews