Build with filtered source

Further nixos module fixes
Add tailwind and esbuild to assets build
Handle domain on session cookies correctly
This commit is contained in:
bluepython508
2023-11-10 20:53:21 +00:00
parent cf9cb3eff5
commit 92edb025fb
7 changed files with 57 additions and 19 deletions

View File

@@ -41,7 +41,7 @@ defmodule SsoBsn.Accounts.UserToken do
end
def build_login_token(user) do
token = Base.encode64(:crypto.strong_rand_bytes(@rand_size))
token = Base.url_encode64(:crypto.strong_rand_bytes(@rand_size))
{token, %UserToken{token: token, context: "login", user_id: user.id}}
end

View File

@@ -8,11 +8,23 @@ defmodule SsoBsnWeb.Endpoint do
store: :cookie,
key: "_sso_bsn_key",
signing_salt: "2YoB6zeO",
same_site: "Lax",
# domain: Application.get_env(:sso_bsn, :session_domain)
same_site: "Lax"
]
socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]
def domain(), do: Application.get_env(:sso_bsn, :session_domain)
def session_options(opts),
do: Keyword.put(opts, :domain, domain())
defmodule RuntimeDomainSession do
def init(opts), do: Plug.Session.init(opts)
def call(conn, opts) do
Plug.Session.call(conn, opts |> Map.update(:cookie_opts, [], &(Keyword.put(&1, :domain, SsoBsnWeb.Endpoint.domain()))))
end
end
socket "/live", Phoenix.LiveView.Socket,
websocket: [connect_info: [session: {__MODULE__, :session_options, [@session_options]}]]
# Serve at "/" the static files from "priv/static" directory.
#
@@ -21,7 +33,7 @@ defmodule SsoBsnWeb.Endpoint do
plug Plug.Static,
at: "/",
from: :sso_bsn,
gzip: false,
gzip: true,
only: SsoBsnWeb.static_paths()
# Code reloading can be explicitly enabled under the
@@ -47,6 +59,6 @@ defmodule SsoBsnWeb.Endpoint do
plug Plug.MethodOverride
plug Plug.Head
plug Plug.Session, @session_options
plug RuntimeDomainSession, @session_options
plug SsoBsnWeb.Router
end

View File

@@ -88,8 +88,7 @@ defmodule SsoBsnWeb.UserRegistrationLive do
{:noreply, socket |> redirect(to: ~p"/users/log_in/#{login_token}")}
{:error, error} ->
dbg(error)
{:noreply, socket |> put_flash(:error, "An error occured")}
{:noreply, socket |> put_flash(:error, "An error occured: #{inspect(error)}")}
end
end