Skip to content

Make current user globally accessible through conn #31

Description

@oliverbarnes

Seems like the only way to access controller context in ja_serializer views is through conn. So for payload attributes that depend on the logged in participant info, we're doing stuff like

# in ProposalController
def index(conn, _params, account, _claims) do
  conn = assign(conn, :account, account)
...

def show(conn, %{"id" => id}, account, _claims) do
  conn = assign(conn, :account, account)
...

# then, in ProposalView
def authored_by_me(proposal, conn) do
  if proposal.author.id == conn.assigns[:account].participant_id do
    "true"
  else
    "false"
  end
end

We could at least make this automatically available on controller actions once the user is logged in, like Rails / Devise's current_user method.

  • look into how other phoenix projects handle this
  • check whether Guardian doesn't already do something like this through its plug

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions