fix: get_from_cookie now correctly handles list return from get_req_header
This commit is contained in:
parent
217ed632fa
commit
6cf955b024
2 changed files with 36 additions and 6 deletions
|
|
@ -69,17 +69,17 @@ defmodule MvWeb.MemberLive.Index.FieldSelection do
|
|||
Returns a map of field names (strings) to boolean visibility values.
|
||||
Returns empty map if no cookie is present.
|
||||
|
||||
Note: This function requires the connection to have cookies parsed.
|
||||
In LiveView, cookies are typically accessed via get_connect_info.
|
||||
Note: This function parses the raw Cookie header. In LiveView, cookies
|
||||
are typically accessed via get_connect_info.
|
||||
"""
|
||||
@spec get_from_cookie(Plug.Conn.t()) :: %{String.t() => boolean()}
|
||||
def get_from_cookie(conn) do
|
||||
# get_req_header always returns a list ([] if no header, [value] if present)
|
||||
case Plug.Conn.get_req_header(conn, "cookie") do
|
||||
nil ->
|
||||
[] ->
|
||||
%{}
|
||||
|
||||
cookie_header ->
|
||||
# Parse cookies manually from header
|
||||
[cookie_header | _rest] ->
|
||||
cookies = parse_cookie_header(cookie_header)
|
||||
|
||||
case Map.get(cookies, @cookie_name) do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue