Skip to content

Commit

Permalink
Fetch the signing salt for the web socket connections from the config (
Browse files Browse the repository at this point in the history
…#1721)

This approach is taken from
https://hexdocs.pm/phoenix/Phoenix.Endpoint.html#socket/3-connect-info

```
Additionally, session_config may be a MFA, such as {MyAppWeb.Auth, :get_session_config, []}, 
to allow loading config in runtime.
```

This allows for the signing salt to not be published and shared between
all running NervesHub installs.
  • Loading branch information
joshk authored Dec 31, 2024
1 parent 9c5db3e commit 1378bb2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/nerves_hub_web/endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ defmodule NervesHubWeb.Endpoint do

alias NervesHub.Helpers.WebsocketConnectionError

def fetch_signing_salt() do
Application.get_env(:nerves_hub, __MODULE__)[:live_view][:signing_salt]
end

@session_options [
store: :cookie,
key: "_nerves_hub_key",
signing_salt: "1CPjriVa"
signing_salt: {__MODULE__, :fetch_signing_salt, []}
]

socket("/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]])
Expand Down

0 comments on commit 1378bb2

Please sign in to comment.